如何處理來自.getjson的數組響應。以下代碼處理ajax請求。jquery ajax數組響應處理
function getinfo()
{
$query="select field_uname_value,field_uaddress_value,field_uphone_value from {content_type_udetails}";
$result= db_query($query);
$i=0;
while($item = db_fetch_object($result))
{
$info[$i++]=array($item->field_uname_value,$item->field_uaddress_value,$item->field_uphone_value);
}
print_r($info);
}
,並返回數組如下
Array
(
[0] => Array
(
[0] => bharath
[1] => 12th street ,ram nagar
[2] => 213124442
)
[1] => Array
(
[0] => Christina
[1] => 77,five corner
[2] => 76874323
)
[2] => Array
(
[0] => Ranjan
[1] => queen towers, 4th layout
[2] => 45745747
)
)
但以下AJAX處理不工作。如何獲得陣列響應
$.getJSON('/knpgetuserinfo.json×tamp'+new Date().getTime(), function(data) {
alert(data[0][0]);
}
json_encode返回一個字符串,而不是PHP中的任何類型的對象,應該只是echo'd! – RobertPitt 2010-10-02 11:28:01
@RobertPitt - 是的,當我在快速測試中打他的代碼時,它提醒我已經更新:) – 2010-10-02 11:28:33