如何用jquery读取json值? [英] how to read the json values with jquery?
问题描述
我的JSON响应就像这样 {items:[{s:2,f:host,m:hi .. :)},]}
我写了下面的代码来读取JSON数据。但没有得到任何价值。警报框也不起作用。如果有人请告诉我我错在哪里...
$ .ajax({
url:ChatHandler.aspx?action = chatheartbeat,
cache:false,
dataType:json,
成功:函数(数据){
$ .each(data.items,function(i,item){
if(item){//修复怪即ie bug
chatboxtitle = item.f;
alert (item.m);
}
});
});
.ajax({
url:ChatHandler.aspx?action = chatheartbeat,
cache:false,
dataType:json,
成功:函数(数据){
.each(data.items,function(i,item){
if(item){// fix strange ie bug
chatboxtitle = item.f;
alert(item.m);
}
});
});
警告可能由以下原因之一起作用:
data.items
为空;然后是
my JSON response is like this { "items":[{"s": "2","f": "host","m": "hi..:)"}, ] }
I wrote the following code to read the JSON data. but not getting the any value. alert box also not working. If any one please inform me where I did mistake ...
$.ajax({
url: "ChatHandler.aspx?action=chatheartbeat",
cache: false,
dataType: "json",
success: function (data) {
$.each(data.items, function (i, item) {
if (item) { // fix strange ie bug
chatboxtitle = item.f;
alert(item.m);
}
});
});
.ajax({
url: "ChatHandler.aspx?action=chatheartbeat",
cache: false,
dataType: "json",
success: function (data) {
.each(data.items, function (i, item) {
if (item) { // fix strange ie bug
chatboxtitle = item.f;
alert(item.m);
}
});
});
Alert might not work by one of the following reasons:
data.items
is empty; then the function in the
这篇关于如何用jquery读取json值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!