jQuery.getJSON不适用于Twitter [英] jQuery.getJSON not working for twitter

查看:85
本文介绍了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=?

这篇关于jQuery.getJSON不适用于Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆