We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1764
    • 680 Posts
    I should probably look into this myself before asking questions here but I’ve been thinking about this for a while and havn’t taken the time to figure out if it’s currently possible.

    Goal:
    Snippets should be able to use custom AJAX methods.

    Problem:
    This means a snippet would have to be able to output XML (or something) and preferable without setting up a separate XML type page to do nothing but handle AJAX requests.

    The easiest way I can think of to do this is to somehow be able to override the tempate so that a blank template is used and return the XML output.

    This could be possible now but would be very ineffecient since a good bit of the tags would have to be parsed before you got to the AJAXified snippet so it could "erase" all of the work you’ve done so far on the template. Ideally the first step in parsing that page would be to evaluate the AJAX snippet so it could basically take over.

    I think that the snippet+plugin merge should handle this nicely, the snippet would be able to output to the page as normal and the plugin part could take over for AJAX requests.


    Basically I guess I just want to thorw this out to get some feedback and suggestions. Does this sound like the best way to handle AJAX in the frontend to you? Would it be better to have a global ajax handler with an OnAjaxCall event? Is there anything I’m missing?
      • 32963
      • 1,732 Posts
      Good points Adam smiley

      The new structure will have two types of events OnHandlePostBack and OnHandleAjaxRequest on the document object.

      It’s a bit hard to explain how it will all work together so I’ll have to get it working before even trying to put together some documentation.




        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 22303 MODX Staff
        • 10,725 Posts
        Can you try and explain how the AJAX calls would work. We all need to understand this, and I don’t need documentation, just some description of the how the methods will interact with the documentObject and the parser...
          • 32963
          • 1,732 Posts
          Quote from: OpenGeek at Jan 04, 2006, 02:35 PM

          Can you try and explain how the AJAX calls would work.  We all need to understand this, and I don’t need documentation, just some description of the how the methods will interact with the documentObject and the parser...

          When a page is loaded it will be treated as an object. This means that the system will invoke specific page events as it does currently in 0.9.1 in addition to a few other event handlers such as OnHandlePostBack and OnHandleAjaxRequest.

          The OnHandleAjaxRequest will be invoked if call is make to the page using client-side (javascript) Request object.

          // client-side
          <form name='myform'>
          Name: <input type="text" name="username" /> 
          <input type="button" value="Submit" onclick="Request.post('myform');" />
          </form>
          <?php
          // some other object code here
          // server-side
          function OnHandleAjaxRequest($event){
             $cli = $this->cms->client;
             $cli->alert('Hello, your name is '.$_POST['username']);
          }
          // some object other code here
          ?>


          The system will then automatically handle the sending of information to and from the server.

          Please see the attached file as it demonstrates some other ajax features of the client extension. In this demo all element manipulation was done from the server. Note: This is not a fully MODxified demonstration.
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.