How come i can't return id using data[0].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
}
});
});
Here's the alert that's returning.
{"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":"[email protected]",
"trainer_group":"","inactive":null}
Any help would be greatly appreciated.
EDIT Here is the php that returns that json:
$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);
I have to loop through and encode each row because, otherwise, the ajax function doesn't think there is json that is returned (and my data var is empty)
alert()call), or the contents of the#alertelement?console.log(data)instead ofalert(data). Then use your browsers developer tools and you can inspect the actual JSON object that is returned.