jQuery.getJSON不适用于twitter

She*_*Pro 0 twitter jquery facebook getjson

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

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

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

但是,当使用jQuery文档中的示例代码调用flicker的api时,它会alert按预期方式提供

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

这是JS Bin上示例代码

我甚至试过Facebook的图形API仍然没有 alert

示例代码中,我尝试使用getJSON调用facebook,twitter,flicker,只提出了闪烁的调用alert.

Mar*_*din 9

您需要将一个回调参数附加到url,以便它成为一个jsonp调用.

http://api.twitter.com/1/statuses/user_timeline.json?callback=?
Run Code Online (Sandbox Code Playgroud)