JSON Array Created in PHP/MySQL incorrectly decoded using JQuery
- by Zak
I am attempting to make an AJAX call to a very small PHP script that should return me an array that could be echo'd and decoded using JQuery. Here is what I have:
My PHP page called to by AJAX:
$web_q=mysql_query("select * from sec_u_g where uid='$id' ");
$rs = array();
while($rs[] = mysql_fetch_assoc($web_q)) {
}
print_r(json_encode($rs));
This outputs:
[{"id":"3","uid":"39","gid":"16"},{"id":"4","uid":"39","gid":"4"},{"id":"5","uid":"39","gid":"5"},{"id":"6","uid":"39","gid":"6"},{"id":"7","uid":"39","gid":"7"},{"id":"8","uid":"39","gid":"8"},{"id":"9","uid":"39","gid":"9"},false]
I don't understand the "false" at the end for one .. But then I send to to JQuery and use:
$.each(json.result, function(i, object) {
$.each(object, function(property, value) {
alert(property + "=" + value);
});
});
This just fails. I try to alert "result" by itself which is set by:
$.post("get_ug.php",{id:txt},function(result){
});
My output alerts are as follows:
1) The key is '0' and the value is '['
2) The key is '1' and the value is 'f'
3) The key is '2' and the value is 'a'
4) The key is '3' and the value is 'l'
5) The key is '4' and the value is 's'
6) The key is '5' and the value is 'e'
7) The key is '6' and the value is ']'
8) The key is '7' and the value is '
' (<-- Yes the line break is there in the alert)
I am exhausted from trying different ideas and scripts. Other than setting a delimiter myself and concatenating my own array and decoding it with a custom script, does anyone have any ideas?? Thank you!!