We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20280
    • 16 Posts
    Scenario:

    * User clicks "calculate" (works)
    * Client POSTs request with params to server (works)
    * Client displays "Waiting" with AJAX-driven <progress> update meter (works, after two 12-hour days of effort)
    * Server performs some huge, massive, intensive operation that might take minutes (works)

    What I'd like now is for the server to send back the next page (offering the view of model that has been calculated), which the client will await.

    This will eliminate the need to load the template, which contains links to JQuery and other libraries that I'd rather not get again.

    $newPage = $modx->FetchTheDataForThePage(params);
    


    I've spent hours looking.

    I see getresources, or maybe it was getresourceids. Returns some kind of list of numbers - irrelevant since I know the resource I want and have everything set up.

    I see the getPage package. This appears geared towards showing paged results. Again, not relevant and major overkill.

    I came across a way to parse the raw data should I need to, which may or may not prove useful (thank you opengeek!):

    https://forums.modx.com/thread/32493/ajax-parsing-modx-before-sending-back-content-to-front-end

    This brings me to the question: What is the name of the $modx function to simply return the raw page data (or, better yet, the PARSED page data) so I can echo it back to the browser (or return it in some more ModX friendly way - doesn't matter as long as it works)?

    Thanks in advance.
      • 3749
      • 24,544 Posts
      How about just putting the data on a page with its own minimal template and forwarding the user to it? That way, MODX will parse any tags on the page for you.

      If you really want to pull the data from a page (assuming that you're using Revolution), you can use getResourceField to pull any field or TV (you can call it in code with $modx->runSnippet()).

      You can also pull data from another Resource into the current page with $modx->sendForward().

      Another way to go is to create a Tpl chunk with placeholders in it, put the placeholder values into an array, and get (and return) the processed chunk with:

      return $modx->getChunk($chunkName, $placeholderArray);
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 20280
        • 16 Posts
        Thank you very much, Bob. You have a gift for teaching, and the ModX community is fortunate to have you.

        Granted, ours is a rather obscure use case as far as ModX goes because it's a scientific application with a long server op - a bit unusual for a web site.

        Yep, target page will be without a template - or at least a minimal one, but loaded into an existing template taking the place of the current [[*content]] (the "Please wait...") leaving the header, footer, and dashboard intact.

        Will play with getresourceField... I saw "field" and was thinking form fields but in a database sense I guess this WOULD be a resource field. But if I can get the entire content, it would work...

        As a last resort, I'll fetch the page directly from my modx_dev database, from modx_site_content.content, but had hoped to avoid that as it violates the opacity of the framework.

        After that, I'll do this (per opengeek):

        <?php
         
        /* get the max iterations tags are processed before processing is terminated */
        $maxIterations= (integer) $modx->getOption('parser_max_iterations', null, 10);
         
        /* parse all cacheable tags first */
        $modx->getParser()->processElementTags('', $data, false, false, '[[', ']]', array(), $maxIterations);
         
        /* parse all non-cacheable and remove unprocessed tags */
        $modx->getParser()->processElementTags('', $data, true, true, '[[', ']]', array(), $maxIterations);
         
        ?>


        It seems AJAX/ModX integration is still somewhat of a frontier.


          • 3749
          • 24,544 Posts
          Thanks for the kind words. If I'm understanding you, another way to go might be to use JS to put the output on the page as it becomes available.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 20280
            • 16 Posts
            Quote from: BobRay at Jan 21, 2013, 04:43 PM
            Thanks for the kind words. If I'm understanding you, another way to go might be to use JS to put the output on the page as it becomes available.

            That's what I ended up doing.

            ModX doesn't care where a request originates (from a sendURLRedirect, from a user click on a link, from a JS AJAX request). Upon request, the page performs its calculation (via a snippet) and Apache sends back the HTML page data I want - parsed by ModX and ready to inject into the DOM tree via .innerHTML, thereby leveraging the AJAX capabilities. No need, I found, to do this from a snippet.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The JQuery load() function even allows you to specify what HTML element of a returned page to insert, so if you use AJAX to load a full MODx page, you only actually insert the part of the page you want. The rest is discarded.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 20280
                • 16 Posts
                Thank you Susan. This is helpful information. Will explore it.
                  • 40447
                  • 165 Posts
                  Another way to go is to create a Tpl chunk with placeholders in it, put the placeholder values into an array, and get (and return) the processed chunk with:
                  return $modx->getChunk($chunkName, $placeholderArray);
                  Bob, that is interesting because this way can also be used in evo.
                    • 3749
                    • 24,544 Posts
                    Yes, getChunk() is the same in Revo and Evo (though the tag syntax for the chunk will be different).
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting