Returning Data from AJAX call

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am calling a series of PHP scripts from AJAX calls and would like to
return XML.  So I have a PHP Script that does this:

function foo(param) {
     // do some stuff, query the db, do some processing, yadda yadda,
end up with a hash table
     resultInXML = formatToXML(results);
     return resultInXML;

function formatXML(param) {
     //  turn the hash table into XML
     return result;

Is this the best way to do this?  Return the return so that it goes
back to wherever the call was made from?  Is there a better way to do



Re: Returning Data from AJAX call

Quoted text here. Click to load it

nothing wrong with that approach. i have an abstract db class with a method
as part if it's interface, queryToXml($sql). that tends to keep the
resultset separate from the '//do stuff' that creates your hash
table...where something may go awry over time with the addition of new code,

there are lots of ways to skin this cat. i think you're on the right track.


Re: Returning Data from AJAX call

Quoted text here. Click to load it

I'd propose to have a look at xAjax , which
makes things really simple:
Register a PHP function or method with xAjax and call it, as if it
were a Javascript function.
xAjax make the function/method pass forth and back.

Moreover, you can post back from your server script multiple actions,
e.g. multiple
replacements of DIV blocks.

xAjax ist really helpful!

Site Timeline