jsonp 循环数据
我有一个返回 jsonp 格式的网络服务。这是代码:
$(document).ready(function(){
$.getJSON("http://api.tubeupdates.com/?method=get.status&lines=central,victoria&return=name&jsonp=?",
function (result){
$.each(result.items, function(item){
$('body').append(item.response.lines[0].name);
});
}
);
});
如果我删除循环,它可以正常工作,但 $.each 循环会失败。 知道我做错了什么吗?
谢谢
毛罗
I have a webservice returning jsonp format. here's the code:
$(document).ready(function(){
$.getJSON("http://api.tubeupdates.com/?method=get.status&lines=central,victoria&return=name&jsonp=?",
function (result){
$.each(result.items, function(item){
$('body').append(item.response.lines[0].name);
});
}
);
});
It works fine if I remove the loop but fails with the $.each loop.
Any idea of what am I doing wrong?
Thanks
Mauro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
响应的
items
属性上没有数组,它看起来像这样:看起来您想要迭代
response.lines
数组,在这种情况下您需要为此:您可以在此处进行测试。
The response doesn't have an array on an
items
property, it looks like this:It looks like you want to iterate the
response.lines
array, in which case you need to do this:You can test it out here.