XMLHttpRequest/mult records

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

Threaded View

Hello everyone,
I had a question about returning multiple records
using XMLHttpRequest and AJAX.  Right now,
I can make a SQL connection and pull informatin from
my DB using php. But that information is just one
record meaning I don't see a way to look
at the xmlhttprequest and say I need value A, or value B
without making multiple calls to the script using AJAX.

Right now, I just put all of the data into one
character delimited string and parse it value by value
to get what I want.

Is there a better way?

If I read Alexey Kulentsov's post correctly, there is not
but maybe I read it wrong.  There was something about
AjaxChannel but that may not be the cure.

Thank You,
--David Williams


Re: XMLHttpRequest/mult records

On Wed, 27 Feb 2008 16:47:48 +0100, David Williams  =

Quoted text here. Click to load it

Give the PHP script input variables by either POST or GET, return either=

XML* or JSON** with the result.


$data = array();
while($row = mysql_fetch_object($result){
    $data[] = $row;
echo json_encode($data);

$document = new DOMDocument();
$root = $document->appendchild('root');
while($row = mysql_fetch_assoc($result){
    $element = $document->createElement($item);
    foreach($row as $name => $value)
        $element->appendChilde($document->createElement($name,$value));    =

echo $document->saveXML();

How to interpret either of those is more relevant to comp.lang.javascrip=
-- =

Rik Wasmus

Site Timeline