返回jquery中的数组值
我需要从PHP返回一个数组,当我成功打印它时,它会显示undefined。如何获取数组的值返回jquery中的数组值,jquery,Jquery,我需要从PHP返回一个数组,当我成功打印它时,它会显示undefined。如何获取数组的值 $.ajax({ type: "POST", url: "test2.php", data : { price : [101, 69, 51], id : [1, 2, 3] }, success: function(response) {
$.ajax({
type: "POST",
url: "test2.php",
data : {
price : [101, 69, 51],
id : [1, 2, 3]
},
success: function(response) {
alert response[0];
}
})
//PHP
使用echo json_encode(…)以jQuery理解的方式对其进行编码。然后,response
是一个数组,就像在PHP代码中一样。使用引号:
price : '[101, 69, 51]'
在对JSON的客户端解析响应中:
alert( JSON.parse(response)[0] )
echo$_请求[“价格”]
可能会导致输出数组
,因为这是PHP中数组的默认字符串表示形式;但是没有用。
alert( JSON.parse(response)[0] )