我正在尝试对一个非常小的 PHP 脚本进行 AJAX 调用,该脚本应该返回一个可以使用 JQuery 回显和解码的数组。这是我所拥有的:
我的 PHP 页面被 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));
这输出:
[{"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]
我不明白最后的“假”..但后来我发送到 JQuery 并使用:
$.each(json.result, function(i, object) {
$.each(object, function(property, value) {
alert(property + "=" + value);
});
});
这只是失败。我尝试自行提醒“结果”,它是由以下设置的:
$.post("get_ug.php",{id:txt},function(result){
});
我的输出警报如下:
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)
尝试不同的想法和脚本让我筋疲力尽。除了自己设置分隔符并连接我自己的数组并使用自定义脚本对其进行解码之外,有没有人有任何想法?谢谢!!