【发布时间】:2016-01-23 13:15:07
【问题描述】:
我的 PHP 脚本返回一个我在 AJAX 调用中接收到的 JSON 对象。
$arr[0] = $resp;
$arr[1] = $e;
return json_encode($arr);
现在在我的 AJAX 调用中,我尝试获取值,但我得到的只是 "/" 或 "'"。
我在 AJAX 中这样做。
dd = JSON.stringify(x.responseText); //this is the response from PHP which is correct I have verified.
alert(dd[0]); //supposed to output $arr[0] but it doesn't
我在这里做错了吗?
【问题讨论】:
-
@u_mulder 问题不在于警报、console.log 或打印,而在于获取正确的数据。
-
Console.log 并查看您在 dd 中的内容。
JSON.stringifybtw 从它的参数中生成 json 字符串。也许你需要JSON.parse? -
@u_mulder 是 JSON.parse 工作 :) 谢谢
标签: javascript php jquery json ajax