为什么我不能使用 data[0].id 返回 id?
$(document).ready(function(){
$.ajax({
type: 'POST',
dataType: "json",
url: '<?php echo matry::base_to('tests/map_it');?>',
success: function (data)
{
alert(data[0])
$('#alerts').html(data);
data[0].id
}
});
});
这是返回的警报。
{"id":19385,"first":"RLY","last":"MAZI",
"trainer_address1":"19 NE 13H CRT",
"trainer_address2":null,"CITY":"MII","STATE":"AL",
"trainer_zip":"33333","trainer_phone":"(721)222-4444","trainer_fax":null,
"trainer_cell":"(213)213- 2133","website_trainer_id":115,"trainer_email":"MO@gmail.COM",
"trainer_group":"","inactive":null}
任何帮助将不胜感激。
编辑这是返回该 json 的 php:
$mapit = sql::results("Select * from event.ACS.trainer where inactive is null or inactive=0");
foreach ($mapit as $row)
{
$return[] = json_encode($row, JSON_FORCE_OBJECT);
}
echo json_encode($return);
我必须遍历并编码每一行,否则,ajax 函数不会认为有返回的 json (并且我的数据 var 为空)