View Full Version : read php array using Jquery

10-15-2010, 09:32 AM
I have a php array in a page suggest.php:

while($row = mysql_fetch_assoc($query))
$res[] = $row['keyword'];

return $res;

i have a jquery script in index.php:

data: "keywords=" + data + "&submit=Find",
//this is where i'd like to make the array from $res


Basically i send a request to suggest.php via jquery ajax,and i get an answer,that is $res.The problem is that i can't figure out how to make a jquery array form $res. I tried :

var hits = $.makeArray(html);,and a few other things,but none of them worked.
Please help me.

10-15-2010, 09:55 AM
Easier to let PHP convert the array into JSON before returning I think, using json_encode (http://www.php.net/manual/en/function.json-encode.php).

10-15-2010, 10:33 AM
I tried your idea,but all i get is a string,something like:


10-15-2010, 11:16 AM
Ok,i've found a way:

var hits = $.parseJSON(html);
works for me.Is it proper usage of this function?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum