Returning Data from AJAX call

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-19-2008
KDawg44
 
Posts: n/a
Default Returning Data from AJAX call

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
Reply With Quote
  #2 (permalink)  
Old 07-19-2008
Dale
 
Posts: n/a
Default Re: Returning Data from AJAX call


"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.


Reply With Quote
  #3 (permalink)  
Old 07-19-2008
justRIA
 
Posts: n/a
Default Re: Returning Data from AJAX call

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!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:58 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0