We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5335
    • 4 Posts
    ok my is this. i want utilize AJAX and i have added into my personal snippet the javascript code and i have added in my snippet the php files. i cal with ajax the file PHP and i obtain one error .
    my applications dont show the $modx->db function or other.
    where is the cause?
    is possible to resolve this?
    thanks

    my javascript framework is prototype and i use the prototype AJAX communication method

    thanks grin
      VENI VIDI VICI
      • 32241
      • 1,495 Posts
      Ehm, are you calling $modx inside the snippet, or you use external file to do it?

      Try to use
      global $modx;

      at the beginning of your code, or inside the function where you use $modx.

      Hope it helps.
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 22303 MODX Staff
        • 10,725 Posts
        I’m not sure exactly what you are doing, but in order to use the $modx object on a request/response of any kind, you have to build the object first. AJAX uses server requests and responses after the page has been generated on the client, so in order for your php file to have access to the MODx object, the script would probably have to create a new instance of it for use during that AJAX request/response cycle.

        It can probably be done, but may not be the best approach from an AJAX performance perspective.

        I think this is the issue at least; just guessing really...
          • 5335
          • 4 Posts
          I have resolved the problem with Pear Package (HTML_AJAX) and i dont utilize the $modx variable tongue

          When ajax call the the php file , the 4modx variable is not under the scope of this file and is not usable.

          But i work (is 3 month) with YAML extension and MODX for a module communication. if the result is good this problem is resolved for all laugh

          Ok thanks for replys and sorry for my orrble english
          bye
            VENI VIDI VICI
            • 8684
            • 29 Posts
            Hi, I don’t know if you remeber your post aout using modx object in a php external file for use with ajax but I try to do the same thing and I don’t know how, can you give more details on how you resolved this issue?
              • 26435
              • 1,193 Posts
              Quote from: elerium at Sep 07, 2007, 09:45 PM

              Hi, I don’t know if you remeber your post aout using modx object in a php external file for use with ajax but I try to do the same thing and I don’t know how, can you give more details on how you resolved this issue?


              Another option is to put your php code in a snippet, then create a new document in the manager and choose the "blank" template for the page template.
              When you POST to that document (for AJAX functions) it will only return the snippet output instead of the whole page template so you don’t get the [*content*] and all that stuff you DON’T want in an AJAX response.

              -sD-
              Dr. Scotty Delicious, Scientist. DFPA.
                Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
                All of the above... in no specific order.


                I send pointless little messages
                • 7885
                • 40 Posts
                please read this document, this clarifies a way to work in MODx using ajax

                http://wiki.modxcms.com/index.php/Use_AJAX_with_modxAPI
                  visit us at www.dospuntocero.cl