jQuery.getJSON不适用于Twitter

jQuery.getJSON不适用于Twitter

问题描述:

任何人都可以告诉我为什么这个jQuery函数不起作用.它不引发alert.

can any one please tell me why this jQuery function is not working. It raises no alert.

$.getJSON('http://api.twitter.com/1/statuses/user_timeline.json?',
  {
      screen_name: 'samajshekhar',
      count: '5',
  },
 function (data) {
      alert('hello world from twitter');
  });   

在提琴手中,我可以看到已经返回了预期的JSON.

In fiddler i can see that expected JSON has been returned.

但是,当使用jQuery文档中的示例代码调用flicker的api时,它会给出预期的alert

However when calling flicker's api using the example code at jQuery documentation it gives an alert as expected

$.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?',
  {
    tags: 'cat',
    tagmode: 'any',
    format: 'json'
  },
  function(data) {
   alert('hello world from flicker');   
  });

这是JS Bin上的示例代码

Here is the sample code on JS Bin

即使Facebook的图形API仍然没有,我也尝试过alert

I tried even with facebook's graph API still no alert

示例代码中,我尝试了对Facebook,twitter,闪烁和仅闪烁调用的getJSON调用. alert被引发.

In sample code i tried getJSON calls to facebook,twitter,flicker and only the flicker's call's alert is raised.

您需要在URL上附加一个回调参数,以使其成为jsonp调用.

You need to append a callback parameter to the url so that it becomes a jsonp call.

http://api.twitter.com/1/statuses/user_timeline.json?callback=?