admin管理员组文章数量:1022777
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 ing:
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
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 ing:
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
Share Improve this question edited Mar 28, 2016 at 21:57 GʀᴜᴍᴘʏCᴀᴛ 9,04820 gold badges90 silver badges160 bronze badges asked Mar 4, 2013 at 13:52 NareshNaresh 2,78110 gold badges48 silver badges80 bronze badges 3-
1
why not
response[0].name
– Arun P Johny Commented Mar 4, 2013 at 13:58 -
is
response
an array? can you check the result forconsole.log(result)
in the console. Add it before the$.each
loop – Arun P Johny Commented Mar 4, 2013 at 14:01 - sorry for wrong ment. i deleted my ment. – Naresh Commented Mar 4, 2013 at 14:04
1 Answer
Reset to default 4try this
$.each(response, function(i, item) {
alert(item.name);
});
example fiddle here
updated
if you need just the first one only thn no need of loop..
alert(response[0].name);
updated fiddle
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 ing:
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
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 ing:
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
Share Improve this question edited Mar 28, 2016 at 21:57 GʀᴜᴍᴘʏCᴀᴛ 9,04820 gold badges90 silver badges160 bronze badges asked Mar 4, 2013 at 13:52 NareshNaresh 2,78110 gold badges48 silver badges80 bronze badges 3-
1
why not
response[0].name
– Arun P Johny Commented Mar 4, 2013 at 13:58 -
is
response
an array? can you check the result forconsole.log(result)
in the console. Add it before the$.each
loop – Arun P Johny Commented Mar 4, 2013 at 14:01 - sorry for wrong ment. i deleted my ment. – Naresh Commented Mar 4, 2013 at 14:04
1 Answer
Reset to default 4try this
$.each(response, function(i, item) {
alert(item.name);
});
example fiddle here
updated
if you need just the first one only thn no need of loop..
alert(response[0].name);
updated fiddle
本文标签: phpjson first index value get in jqueryStack Overflow
版权声明:本文标题:php - json first index value get in jquery - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745563781a2156325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论