Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回jquery中的数组值_Jquery - Fatal编程技术网

返回jquery中的数组值

返回jquery中的数组值,jquery,Jquery,我需要从PHP返回一个数组,当我成功打印它时,它会显示undefined。如何获取数组的值 $.ajax({ type: "POST", url: "test2.php", data : { price : [101, 69, 51], id : [1, 2, 3] }, success: function(response) {

我需要从PHP返回一个数组,当我成功打印它时,它会显示undefined。如何获取数组的值

$.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] )