We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36932
    • 39 Posts
    boundaryfunctions Reply #1, 15 years ago
    Hello everyone,

    I've been searching for a solution on this one and I bet it's pretty easy. I'm quite new to modX and all solutions I found we're for Evo, but I need it for Revolution.

    So here's the problem:
    I need a plugin that checks this:
    if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')

    and if it is the case, it should output only the content-variable of the requested page. I will use it for simple Ajax, in particular opening some pages in Lightboxes while having the normale pages as a fallback.

    I'd be so glad if anyone here could point me in the right direction.
    With kind regards,
    Marc
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Any javascript solution for Evo should work the same for Revo. Neither version in any way restricts Javascript/AJAX functions, which are all done in the browser. The only difference would be in the back-end PHP processing.

      Your template, chunk or content can have any Javascript you want. MODx just treats it as any other HTML code. There are even API functions so you can insert the Javascript dynamically from a snippet.

        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
        • 36932
        • 39 Posts
        boundaryfunctions Reply #3, 15 years ago
        Thanks for the quick response!

        I don't have any problems with the Javscript, I'm using the jQuery .load() function to get done what I need and it works like a charm. What I need is a PHP-plugin for modx!

        It should check as early as possible in the processing of the page whether the Client has set "$_SERVER('HTTP_X_REQUESTED_WITH')" to "xmlhttprequest". This would be the case, if I request the URL with an asynchronous request by jQuery. This is what the small snippet above was about, just to be able to differentiate between normal client requests and AJAX-requests.

        The functionality should be that if the page is requested via AJAX, modx should send only the content of the content-variable of the requested page, with no templating going on at all. This way it would be easy to insert this via js into the already loaded page.

        It would be something very similiar to this: https://forums.modx.com/index.php?topic=37430.0%3bwap2
        My problem is, that I really don't know:

        • a) on which event my code should be code, and
        • b) how i can change the normal output to only the contens of the current pages content variable
        I really can't find it anywhere, which api-calls i will have to use in revo. Lack of documentation and probably also a bad search.

        Thanks anyway for the quick help. If anyone can hive me a hint on the api calls i would need, please post here!
          • 34945
          • 15 Posts
          Try to change the MobileTemplate plugin which is available in MODX Package Manager. IMHO it does the same - if it detects mobile device in headers, it changes the document's template to mobile one. You can try to replace the mobile detection routines with your
          if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
          etc.

          Or, if some users might turn off javascript in their browsers you can try the next. Insert your AJAX fragment into the whole page, as when your AJAX content is already inserted into DOM, then call your jQuery .load function like this:
          $('#your-container').load('/ajax-url.php #content');
          

          This will download full page via AJAX, then take the #content element and insert it into the #your-container element.
          More about .load() function:
          http://api.jquery.com/load/ - see the "Loading Page Fragments" section.
          Good luck!