Hi All,
The start of the GSoC coding period is just around the corner, and I would like to start writing some useful code as soon as possible. I have a few questions before I start doing that though. In my proposal, I have mentioned one of my tasks as writing functions that will wrap the output of AJAX requests in well-formed XML. Over the last few days, I have been trying to figure out how to do this. Should I use output buffering at the start of an ajax request, read the entire output buffer into a string variable and then construct either a DOM or a SimpleXML object from that string when the request ends? Or, is there a better way of doing this?
Also, when I checked out the latest version from git, I could see that a jQuery JSON plugin has been added in the js/jquery folder. If this plugin is being used, should the output for AJAX requests be in JSON instead of XML? I feel it would be a lot more easier to handle the output in JSON rather than XML.
For the AJAX calls, do I use the jQuery's $.get/$.post/$.ajax methods directly or should I build wrapper functions around them?
I found a plugin that makes it easy to handle a page with frames, the jQuery FrameReady plugin [0]. Has anybody used this plugin with phpMyAdmin (or in any other projects)? It makes a lot of sense to use this, as I had context issues when I was trying to write the patch for paginating the table.
Last, where should I put all the jQuery scripts that will be written over the next few weeks in the tree? Should I keep it in a js/ajax folder for the period of this summer, and then merge it later into the js folder after the features have been sufficiently tested?
I guess that's a lot of questions! Thank you for all the help :)
------------------------- [0] - http://ideamill.synaptrixgroup.com/?p=6 -------------------------
Ninad S. Pundalik Twitter: @ni_nad | Identica : @ninad | http://ninadpundalik.co.cc/blog GPG Key Fingerprint: 2DF7 B856 C75E C9F9 0504 C0EF D456 1946 7C45 2C69
2010/5/21 Ninad Pundalik ninadsp16289@gmail.com:
Also, when I checked out the latest version from git, I could see that a jQuery JSON plugin has been added in the js/jquery folder. If this plugin is being used, should the output for AJAX requests be in JSON instead of XML? I feel it would be a lot more easier to handle the output in JSON rather than XML.
I added it because my Setup script uses JSON replies for validation. Besides, parsing JSON (both constructing and parsing) is faster than XML, requires less bandwidth and less code to read the response, so I believe we should stick with that. phpMyAdmin requires PHP 5.2, and since that version the extension for building JSON responses is part of PHP core.
For the AJAX calls, do I use the jQuery's $.get/$.post/$.ajax methods directly or should I build wrapper functions around them?
If this intermediate layer can be justified, why not.
Ninad Pundalik a écrit :
Hi All,
The start of the GSoC coding period is just around the corner, and I would like to start writing some useful code as soon as possible. I have a few questions before I start doing that though. In my proposal, I have mentioned one of my tasks as writing functions that will wrap the output of AJAX requests in well-formed XML. Over the last few days, I have been trying to figure out how to do this. Should I use output buffering at the start of an ajax request, read the entire output buffer into a string variable and then construct either a DOM or a SimpleXML object from that string when the request ends? Or, is there a better way of doing this?
Hi Ninad,
In your deliverables you wrote: "2. Functions that will wrap the output in well formed XML, so that jQuery can correctly parse the response and insert the right content at the right location in the page."
I guess that this would not be necessary if you use JSON?
Also, when I checked out the latest version from git, I could see that a jQuery JSON plugin has been added in the js/jquery folder. If this plugin is being used, should the output for AJAX requests be in JSON instead of XML? I feel it would be a lot more easier to handle the output in JSON rather than XML.
Indeed.
For the AJAX calls, do I use the jQuery's $.get/$.post/$.ajax methods directly or should I build wrapper functions around them?
Please do not use wrappers that do nothing; as a bad example in PHP:
// I find cool to use my_echo('Hello'); function my_echo($message) { echo $message; }
Last, where should I put all the jQuery scripts that will be written over the next few weeks in the tree? Should I keep it in a js/ajax folder for the period of this summer, and then merge it later into the js folder after the features have been sufficiently tested?
I suggest to put them under /js.
Hi Marc,
On 21 May 2010 17:27, Marc Delisle marc@infomarc.info wrote:
Ninad Pundalik a écrit :
Hi All,
The start of the GSoC coding period is just around the corner, and I would like to start writing some useful code as soon as possible. I have a few questions before I start doing that though. In my proposal, I have mentioned one of my tasks as writing functions that will wrap the output of AJAX requests in well-formed XML. Over the last few days, I have been trying to figure out how to do this. Should I use output buffering at the start of an ajax request, read the entire output buffer into a string variable and then construct either a DOM or a SimpleXML object from that string when the request ends? Or, is there a better way of doing this?
Hi Ninad,
In your deliverables you wrote: "2. Functions that will wrap the output in well formed XML, so that jQuery can correctly parse the response and insert the right content at the right location in the page."
I guess that this would not be necessary if you use JSON?
If we use JSON, we would still need equivalent functions for wrapping the plain HTML (and JavaScript) generated on the fly by the PHP scripts. The use case which I had in mind for the above functions is the following:
1. Script a.php has sections of code foo, bar, bar1, baz and baz1 which are executed in the same sequence when a normal HTTP request is made for that page. 2. When an Ajax request is made for a.php, however, only sections foo, bar1 and baz1 are to be executed as bar and baz generate navigation links (or some other inconsequential division on the page) which we do not need in an Ajax request. 3. Hence, I can put a check for $_REQUEST['ajax_request'] and conditionally execute only foo, bar1 and baz1 if it's an Ajax request. Now, the output generated would be a series of HTML divisions, with unique ids. 4. If the page has been constructed in such a way that the output generated by foo, bar1 and baz1 are not continuous, the output generated in the previous step must have each of the divisions separate, so that I can use jQuery and place the HTML of each one at the correct location on the page.
If we use plain HTML, jQuery cannot traverse the data it receives from the Ajax call and insert different divisions at different places. Initially, I wanted to wrap the output by foo, bar1 and baz1 in XML nodes or as elements of a JSON array. However, I've just realized, that I can spare myself all this trouble and insert all the data that is sent as a response in a hidden temporary division on the page and then use jQuery to insert each section at the proper place.
The only concern that I have with this approach is that the JavaScript/jQuery code will be tightly coupled with the page for which it is written. A possible work around to this concern is to use jQuery's iterative nature and 'register' the different elements where the content will be replaced, and use a generic callback function at the end of the Ajax call to do the hard work.
As for simple actions (like deleting an entry from a table or reloading privileges), I will use JSON to generate success/error messages and not XML.
Please do not use wrappers that do nothing; as a bad example in PHP:
Understood. :)
I suggest to put them under /js.
This directory already has .js files for some pages (eg.: server_privileges.js). Where such files do not exist, I will create a .js file in this directory with the appropriate name.
Ninad S. Pundalik Twitter: @ni_nad | Identica : @ninad | http://ninadpundalik.co.cc/blog GPG Key Fingerprint: 2DF7 B856 C75E C9F9 0504 C0EF D456 1946 7C45 2C69