我想循环从PHP
返回的数组。但仍然没有办法。例子是〜如何在从jQuery Ajax成功返回的数组中循环?
PHP:
$items = array();
$items["country"] = "North Korea",
$items["fruits"] = array(
"apple"=>1.0,
"banana"=>1.2,
"cranberry"=>2.0,
);
echo json_encode($fruits);
的jQuery:
$.ajax({
url: "items.php",
async: false,
type: "POST",
dataType: "JSON",
data: { "command" : "getItems" }
}).success(function(response) {
alert(response.fruits.apple); //OK
// <------ here, how do i loop the response.fruits ? -----
});
那我怎么才能循环知道我有哪些水果吗?