如果你的 PHP 数组是这样的:
$myArray = array ( 'results' => array (
array ( 'id' => '153',
'title' => 'xyz',
'description' => 'abc' ),
array ( 'id' => '154',
'title' => 'xyy',
'description' => 'abb' )
),
'filter_color' => array ( 'Red' => 1, 'Blue' => 8 ),
'count_rows' => array ( 'rows' => '10' )
);
这会给你这个回应使用json_encode()
:
{
"results":
[ {"id":"153","title":"xyz","description":"abc"},
{"id":"154","title":"xyy","description":"abb"} ],
"filter_color":{"Red":1,"Blue":8},
"count_rows":{"rows":"10"}
}
你的 jQuery 看起来有点像这样:
$.ajax({
url: "http://example.com",
success: function(data) {
// Then you can do this to print out the description of each result
// in the browser console... or append the info to a table
for(var i in data.results) {
console.log(data.results[i].description);
$("table").append("<tr><td>" + data.results[i].title + "</td><td>" + data.results[i].description + "</td></tr>");
}
}
});