简体   繁体   English

尝试获取JSON Twitter时间轴时得到空结果,但是当我将其复制并粘贴到浏览器中时它可以工作

[英]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.

相关问题 jQuery 仅在我将其粘贴到控制台时才有效 - jQuery only works when I paste it in the console 尝试从其他域获取json数据时获取未定义 - Getting undefined when trying to get json data from other domain 在尝试向其发送请求时未找到节点app.get,但在浏览器中有效 - Node app.get not found when trying to make a post request towards it, but works in browser Twitter使用“prefetch”时没有结果,但使用“远程”JSON - Twitter typeahead no result when using “prefetch”, but working with “remote” JSON 为什么在尝试解析这个 json 对象时会出错? - Why do I get error when trying to parse this json object? 用于获取Twitter时间轴的正确URL - Correct URL for getting Twitter timeline 当我从 controller 返回 json 结果以查看时,它将在浏览器本身上打印或显示 - when i return json result from controller to view it is going to print or display on browser itself 浏览器复制/粘贴组件 - Browser Copy/Paste the components 当我尝试使用jQuery从Twitter API获取数据时收到错误请求(400) - Getting a Bad Request (400) when I try to GET data from the Twitter API using jQuery 尝试复制时粘贴输入字段的值:无法读取未定义的属性“ nodeType” - When trying to copy paste the value of an input field: Cannot read property 'nodeType' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM