开发者

Getting followers from Twitter API via json results nothing in jQuery

开发者 https://www.devze.com 2023-01-16 10:35 出处:网络
I\'m trying to include list of my followers on my site. Here\'s my code: $.getJSON(\'http://twitter.com/statuses/f开发者_如何学编程ollowers.json?screen_name=username\',function(data){

I'm trying to include list of my followers on my site. Here's my code:

$.getJSON('http://twitter.com/statuses/f开发者_如何学编程ollowers.json?screen_name=username',function(data){
    alert(data);
});

However, nothing happens. No errors, other js still works, just this doesn't work. What is wrong?

Martti Laine

Ps. I'm using jQuery for this, as page loads faster, when not using php. Content is shown faster.


You need to trigger JSONP by adding this to the end of your URL: &callback=?, like this:

$.getJSON('http://twitter.com/statuses/followers.json?screen_name=username&callback=?',function(data){
    alert(data);
});​

You can see it getting a response here. Without doing this it's attempting to make an XmlHttpRequest fetch of the data, which is blocked by the same-origin policy.

0

精彩评论

暂无评论...
验证码 换一张
取 消