On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I wanted to do some queries in my DB through AJAX and had troubles with the response. JSON is integrated in Prototype, but not in PHP and i didn’t wanted to use any PHP toolkit. I wanted to use XML feedback with an interpreter on the client side and a manual output on the server side.
    Finally, i never got the xml parser to work on the client side, so I thought about the good old days of DOS, when I programmed in QBasic and QuickC. Sequential file with \t and \n separated data :

    + each item is on its line, separated from the other by a \n
    + each field is divided from the others by a \t

    This way, you can create a manual parser in around 4 lines of javascript by using the split() function :

    var myresponsefields = request.responseText.split('\t');


    then paste the data at the good place. Prototype helps a lot there with helper functions like Array.each() wich let you call a function for each item of the array.
      Blaise Bernier

      www.medialdesign.com - Solutions for small business, hosting, design and more!
    • Use JSON. XML is way too big, and it takes time to parse XML on Javascript, while JSON is a buiilt data format for Javascript, so you basically doesn’t spent time to parse the response, instead you just do eval(’var response = JSON’). It’s a lot smaller compare to XML, considering all the extra tags, while in JSON you only required {}, [], "", or coma. To encode/decode JSON format in php, use JSON-PHP. Look for it in google, usually you can download it from pear.php.net.

      The way you ask for request on your server side, you need to do it using get or post method, usually this is provided by prototype. If you want to postback a form, do Form.serialize in full Prototype.

      Hope that helps.
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
      • thanks! Even then, I almost find it easier with \t and \n, but in my next module I’m gonna use it to follow the standards.

        thanks!

        Bye,

        Blaise
          Blaise Bernier

          www.medialdesign.com - Solutions for small business, hosting, design and more!