This is a discussion on Returning Data from AJAX call within the PHP Language forums, part of the PHP Programming Forums category; Hi, I am calling a series of PHP scripts from AJAX calls and would like to return XML. So I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
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 this? Thanks. Kevin |
|
|||
|
"KDawg44" <KDawg44@gmail.com> wrote in message news:ec577223-f439-4fd2-b6ba-cf0c0d51aa66@k30g2000hse.googlegroups.com... > Hi, > > 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 > this? 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, etc.. there are lots of ways to skin this cat. i think you're on the right track. cheers. |
|
|||
|
On 19 Jul., 21:06, KDawg44 <KDaw...@gmail.com> wrote:
> Hi, > > 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: I'd propose to have a look at xAjax http://xajaxproject.org/ , 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! |