...

View Full Version : read php array using Jquery



attasz
10-15-2010, 10: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:


$.ajax({
type:"GET",
url:"incs/search.php",
data: "keywords=" + data + "&submit=Find",
success:function(html){
//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.

SB65
10-15-2010, 10: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).

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

["temperature","temperature","temperatures","attempts"]

attasz
10-15-2010, 12:16 PM
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