我有这个PHP代码
$ids = array(1,2,3);
$names = array("cat","elephant","cow");
$originalSettings = array ('ids'=>$ids,'names'=>$names);
$jsonSettings = json_encode($originalSettings);
echo $jsonSettings;
这是jQuery代码
$.post("ajax.php", {},
function(data){
data.ids.each(function(i) {
alert(data.names[i]);
}
//is it possible to receive the arrays and navigate them
}, "json");
如何使用json传递数组并在javascript中接收它们?
由于
答案 0 :(得分:1)
尝试:
function(data) {
$.each(data.array1, function(i) {
alert(data.array2[i]);
});
}