We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17895
    • 209 Posts
    Hi all,
    I want to start using AJAX technology and found that it is easy with simple PHP pages, but not that easy with MODx. Questions:
    - I cannot write JavaScript code directly in a page (i.e. using the content editor), even if editing HTML: FCKeditor likes to mess the JavaScript code. The best way I found is to create a chunk and write the snippet there.
    - As for PHP side, I can of course write a PHP page that process async request and send the XML/JSON/whatever reply, but I have to upload that file and this is odd. I use a snippet and a blank template (with only the [*content*]). In this way I can put the code in the snippet and the snippet in a page. It’s more MODxish. Is there any better way to do this? I see a index-ajax.php in the root directory, but I cannot have anything better than a "Cannot load requested ajax handler" message
      Daniele "MadMage" Calisi
      • 17895
      • 209 Posts
      It seems that this topic so simple has no answer... do I have to think that nobody used AJAX here?
        Daniele "MadMage" Calisi
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: madmage at Dec 19, 2006, 04:07 PM

        I want to start using AJAX technology and found that it is easy with simple PHP pages, but not that easy with MODx. Questions:
        - I cannot write JavaScript code directly in a page (i.e. using the content editor), even if editing HTML: FCKeditor likes to mess the JavaScript code. The best way I found is to create a chunk and write the snippet there.
        It’s not any easier or harder with MODx at this point. And don’t use RTE’s to enter markup and javascript if you want control over it. RTE’s are for end-users to be able to update small, isolated sections of content that can’t mess up the layout of the site.

        Quote from: madmage at Dec 19, 2006, 04:07 PM

        - As for PHP side, I can of course write a PHP page that process async request and send the XML/JSON/whatever reply, but I have to upload that file and this is odd. I use a snippet and a blank template (with only the [*content*]). In this way I can put the code in the snippet and the snippet in a page. It’s more MODxish. Is there any better way to do this? I see a index-ajax.php in the root directory, but I cannot have anything better than a "Cannot load requested ajax handler" message
        I’m not exactly following. You need to provide the ajax handler. The index-ajax.php just helps you get access to the MODx database configuration details if you need db access in your handler.
          • 17895
          • 209 Posts
          Quote from: OpenGeek at Dec 23, 2006, 12:29 PM

          Quote from: madmage at Dec 19, 2006, 04:07 PM

          - As for PHP side, I can of course write a PHP page that process async request and send the XML/JSON/whatever reply, but I have to upload that file and this is odd. I use a snippet and a blank template (with only the [*content*]). In this way I can put the code in the snippet and the snippet in a page. It’s more MODxish. Is there any better way to do this? I see a index-ajax.php in the root directory, but I cannot have anything better than a "Cannot load requested ajax handler" message
          I’m not exactly following. You need to provide the ajax handler. The index-ajax.php just helps you get access to the MODx database configuration details if you need db access in your handler.

          When you say "AJAX handler" you mean a PHP page, right?
          but that page cannot be in the site_content table, it has to be a separated file, right?
            Daniele "MadMage" Calisi
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: madmage at Dec 23, 2006, 04:50 PM

            When you say "AJAX handler" you mean a PHP page, right?
            but that page cannot be in the site_content table, it has to be a separated file, right?
            That’s right. Having virtual MODx documents as AJAX handlers in this version of MODx is, well, not the best approach IMO, because you are bootstrapping a lot of unnecessary code to that end. The purpose of providing index-ajax.php was as a temporary solution for accessing the MODx database in your own AJAX code (separate PHP script). In the next release, you will be able to do what you are describing as the new MODx core coming in 0.9.7 only loads what it needs to. In addition, I plan to have a basic class you can extend to handle typical AJAX requests as "documents" managed by MODx, along with some other surprises.
              • 17895
              • 209 Posts
              Quote from: OpenGeek at Dec 23, 2006, 05:01 PM

              Quote from: madmage at Dec 23, 2006, 04:50 PM

              When you say "AJAX handler" you mean a PHP page, right?
              but that page cannot be in the site_content table, it has to be a separated file, right?
              That’s right. Having virtual MODx documents as AJAX handlers in this version of MODx is, well, not the best approach IMO, because you are bootstrapping a lot of unnecessary code to that end. The purpose of providing index-ajax.php was as a temporary solution for accessing the MODx database in your own AJAX code (separate PHP script). In the next release, you will be able to do what you are describing as the new MODx core coming in 0.9.7 only loads what it needs to. In addition, I plan to have a basic class you can extend to handle typical AJAX requests as "documents" managed by MODx, along with some other surprises.

              So I’m looking forward for 0.9.7! ;-)
                Daniele "MadMage" Calisi