$.ajax({
url: postUrl,
type: 'GET',
dataType: 'json',
data: { "id": num },
contentType: "application/json; charset=utf-8",
success: function (data) {
$.each(data, function (id, allFollowers) {
result += 'Title : ' + **data** + '<br/>';
});
我可以在调试模式下看到这些值,但是它返回空错误。?
答案 0 :(得分:0)
我认为您的错误与使用$.each
函数有关。您应该使用以下代码来引用数据:
$.each(data, function (id, follower) {
result += 'Title : ' + follower + '<br/>';
});
有关更多信息,请参阅此jQuery API Documentation。
答案 1 :(得分:0)
根据您的屏幕截图,我假设数据看起来像这样:
//data is an object, with an array of allFollowers objects
var data = {
"allFollowers": [{
"AlternateText": "no photo",
"profileImage": "http://foo.com/foo",
"screenName": "foo",
"userID": 15785100
},
{
"AlternateText": "no photo",
"profileImage": "http://bar.com/bar",
"screenName": "bar",
"userID": 12345678
}
]
};
您仅在data
上/而不是在其子数组(allFollowers
)上进行迭代。因此,您必须更深入一点:
$.each(data, function(key, obj) {
$.each(obj, function(i, value){
console.log("screen name %i: %o, User ID: %o", i, value.screenName, value.userID);
})
})
控制台:
screen name 0: "foo", User ID: 15785100
screen name 1: "bar", User ID: 12345678
Hth ...