您将必须返回以json形式编码的数组,如下所示
$array = array("a","d");
echo json_encode($array);
然后你可以在javascript中访问它,将其转换回数组/对象
var result = eval(retuned_value);
您还可以使用for循环遍历所有数组元素
for (var index in result){
// you can show both index and value to know how the array is indexed in javascript (but it should be the same way it was in the PHP script)
alert("index:" + index + "\n value" + result[index]);
}
在你的代码中它应该看起来像:
$array = array("a","d");
echo json_encode( $array );
jQuery脚本
$.ajax({
type: 'POST',success: function(result) {
if(result){
resultObj = eval (result);
alert( resultObj );
}else{
alert("error");
}
}
});