[英]Getting an empty result when trying to get JSON twitter timeline but it works when I copy and paste it into a browser
I'm using the following to try and get the twitter timeline of a user. 我正在使用以下方法来尝试获取用户的Twitter时间轴。 When I view the network traffic in Firebug it shows a 200 response code, but the line is red and the results are blank. 当我在Firebug中查看网络流量时,它显示200响应代码,但该行为红色,结果为空白。 If I take the same url and paste it into a browser I get the json as expected. 如果我使用相同的URL并将其粘贴到浏览器中,则将按预期获取json。 Is there something I'm doing wrong? 我做错了什么吗? You can see I put an alert inside there and it's never hit. 您可以看到我在其中放了一个警报,它从未被击中。 I get no javascript error either though, so I'm not sure where the problem lies. 我也没有收到JavaScript错误,因此我不确定问题出在哪里。
jQuery.getJSON('http://api.twitter.com/1/statuses/user_timeline.json?count=10&screen_name=name_removed&include_rts=true', function(data)
{
alert('test');
var items = [];
//Code to handle result
});
I've checked this in Firebug and the IE developer tools. 我已经在Firebug和IE开发人员工具中进行了检查。 Firebug shows it in red as if there was a problem but a 200 reponse code. Firebug以红色显示它,好像有问题,但是响应代码为200。 IE developer tools and fiddler don't even show the URL was ever called. IE开发人员工具和提琴手甚至没有显示该URL被调用过。
我认为这是由于同源政策
You'll have to do something like this(if this is the same error I'm thinking of). 您将必须执行类似的操作(如果这是我正在考虑的相同错误)。
$.ajax({
dataType: 'jsonp',
url: 'http://api.twitter.com/1/statuses/user_timeline.json?count=10&screen_name=name_removed&include_rts=true?callback=?',
success: function (data) {
console.log(data);
}
});
The callback parameter is important. 回调参数很重要。
Please see this. 请看这个。
http://en.wikipedia.org/wiki/JSONP http://en.wikipedia.org/wiki/JSONP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.