I am generating JSON via an Ajax loop which I am successfully iterating and getting results. I need only the first index value of JSON which is name
and I am doing this as in jQuery:
PHP
$jsonRows[] = array(
"name" => $result['name'],
"datetime" => $result['datetime'],
"place" => $result['place'],
);
print_r(json_encode($jsonRows));
suppose the values are coming:
name: raj,
datetime: 2013-03-01 16:50:21,
place: India
name: jatin,
datetime: 2013-03-01 20:50:21,
place: US
name: raman,
datetime: 2013-03-03 01:50:21,
place: Japan
I need only name: raj but I am not getting this value:
JavaScript
$.each(response, function(i, item) {
alert(item(0).name);
});
error: object is not a function
response[0].nameresponsean array? can you check the result forconsole.log(result)in the console. Add it before the$.eachloop