如何在php中将数组返回给ajax调用,
阿贾克斯电话:
$.post('get.php',function(data){
alert(data)
});
get.php
$arr_variable = array('033','23454')
echo $arr_variable;
在alert(data)中,它显示为Array(即仅文本),当我显示data [0]时,显示Array的第一个字母,即A。
有什么建议么 ?我做错了
用于像这样对数组进行编码
$data['result'] = $arr_variable;
echo json_encode($data);
exit;
并在成功函数中尝试使其parseJSON
像
$.post('get.php',function(data){
var res = $.parseJSON(data);
alert(res.result)
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句