We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7885
    • 40 Posts
    Hi guys i was wondering if sort of MODx API for Ajax snippets exists... i’m really interested in found some way to use modx dbAPI in my php code to make ajax snippets

    i have been looking in the ajaxsearch code but it doesn’t use the dbapi, just plain mysql queries for ajax calls why is that?

    example
    if($ajaxSearch){
    common sql} else{
    dbapi access}

    i want to use api functions like makeArray or getChunk... but i cant (what i’m doing wrong??)

    thanks guys!
      visit us at www.dospuntocero.cl
      • 22303 MODX Staff
      • 10,725 Posts
      Why not write snippets for your Ajax requests and execute them as documents in your site? This is how I use Ajax with MODx when I want to have access to the MODx API. Just have it return the JSON or HTML (or whatever form of) response.
        • 26435
        • 1,193 Posts
        I also have had success with what OpenGeek recommends.
        I create a snippet to process the ajax request(s) then create a new document with a blank template (so no other output is generated) and place only my AJAX snippet call on that page.

        Then in my site where I want to use POST or GET to send an AJAX message and get a response I post my calls to that document using Hijax.
        Let’s say this blank page with the AJAX snippet call on it has a document ID of 55.

        In my page where I have a form for sending asynchronous messages, I use javascript (I prefer jQuery) to hijack the form and instead of posting it normally, post it to "index.php?id=55".

        Please feel free to ask for more details if you would like them.

        -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
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: Dr. at Sep 13, 2007, 07:39 PM

          In my page where I have a form for sending asynchronous messages, I use javascript (I prefer jQuery) to hijack the form and instead of posting it normally, post it to "index.php?id=55".
          You can even post to [~55~] to respect friendly urls, if you care wink
            • 26435
            • 1,193 Posts
            Quote from: OpenGeek at Sep 13, 2007, 10:13 PM

            You can even post to [~55~] to respect friendly urls, if you care wink
            True... in a MODx document, but this is all happening in an external javascript.js file.
            I suppose I should just make my javascript files MODx documents. Hell, that would make them a bit more dynamic

            -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
              • 20289
              • 958 Posts
              Wiki worthy topic if there is not yet and someone have time to do, perhaps some tutorial would address new commers to Ajax and MODx lipsrsealed
                [img]http://i10.tinypic.com/52c4eir.gif[/img][/td]
                [td][Wiki] [Persian support forum]
                [SVN] [RTL SVN Branch] [bugs] [FishEye+Crucible] [Learn MODx!] | [My Google Code]
                [font=tahoma][برای دسترسی به راهنمای فارسی به [url=http://www.modxcms.ir]
                • 7231
                • 4,205 Posts
                Quote from: MotSmart at Sep 14, 2007, 04:52 AM

                Wiki worthy topic if there is not yet and someone have time to do, perhaps some tutorial would address new commers to Ajax and MODx lipsrsealed
                Yes, this would be a nice wiki topic grin
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don't know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 7885
                  • 40 Posts
                  Quote from: dev_cw at Sep 14, 2007, 09:00 AM

                  Quote from: MotSmart at Sep 14, 2007, 04:52 AM

                  Wiki worthy topic if there is not yet and someone have time to do, perhaps some tutorial would address new commers to Ajax and MODx lipsrsealed
                  Yes, this would be a nice wiki topic grin

                  thanks guys, i’ll start the tests right now, if i have some doubts, i’ll ask again, when i finished i’ll post it in the wiki both spanish and english (for that reason my english sucks sometimes...)

                  right now i have some working stuff, using index-ajax.php, but my main problem is i cant do modx logic (DBAPI access or $modx-> stuff) in an external php file, hope this could be resolved with your idea of blank file with snippet (i’m not a seasoned php developer, just a noob good only with actionscript)

                  thanks pals
                    visit us at www.dospuntocero.cl
                    • 7885
                    • 40 Posts
                    well guys as i promised, i have posted in the wiki my "framework" to do ajax stuff in MODx smiley thanks for your guidance, i’m really happy to see lots of heavyweights in answering my question, so in retribution I contribute to the comunity with my new know how laugh


                    http://wiki.modxcms.com/index.php/Use_AJAX_with_modxAPI
                      visit us at www.dospuntocero.cl
                      • 26435
                      • 1,193 Posts
                      Quote from: dospuntocero at Sep 18, 2007, 10:15 PM

                      well guys as i promised, i have posted in the wiki my "framework" to do ajax stuff in MODx smiley thanks for your guidance, i’m really happy to see lots of heavyweights in answering my question, so in retribution I contribute to the comunity with my new know how laugh


                      http://wiki.modxcms.com/index.php/Use_AJAX_with_modxAPI

                      Thanks for posting a wiki on this!
                      I have also been using this technique for a while. You have done a great job of documenting the steps.

                      -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