确切的字符串getJSON和callback =? [英] exact string to getJSON and callback=?

查看:164
本文介绍了确切的字符串getJSON和callback =?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让getJSON使用JSONP对象,但是我不知道如何构建URL:

I'm trying to make getJSON to use JSONP object, but I can't figure out how to build the url:

,例如: http://graph.facebook.com/?ids=http://legrandj .eu / article / blouse_ghost_dream

我应该如何添加callback =?参数?

where and how should I add "callback=?" parameter?

谢谢

d。

推荐答案

& callback =?追加到URL。

$.getJSON('http://graph.facebook.com/?ids=http://legrandj.eu/article/blouse_ghost_dream&callback=?', function(data) {
    // ..
});
// Or (more clean): 
$.getJSON('http://graph.facebook.com/?callback=?',
    {
        ids: 'http://legrandj.eu/article/blouse_ghost_dream'
    },
    function(data) {
        // ...
    }
);

鉴于此代码,jQuery创建并插入< script src = http://graph.facebook.com/?ids=http://legrandj.eu/article/blouse_ghost_dream&callback=jQuery171022388557461090386_1332329918803&_=133232991983\" > 。 URL的解释:

Given this code, jQuery creates and inserts a <script src="http://graph.facebook.com/?ids=http://legrandj.eu/article/blouse_ghost_dream&callback=jQuery171022388557461090386_1332329918803&_=133232991983">. Explanation of the URL:

  • Base URL: http://graph.facebook.com/?ids=http://legrandj.eu/article/blouse_ghost_dream
  • Callback handler: &callback=jQuery171022388557461090386_1332329918803
    jQuery replaces ? in callback=? with an unique temporary identifier.
  • Cache-breaking: &_=133232991983

FB API以以下格式返回响应( JSONP ):

The FB API returns a response in the following format (JSONP):

/**/ jQuery171022388557461090386_1332329918803({
   "http://legrandj.eu/article/blouse_ghost_dream": {
      "id": "http://legrandj.eu/article/blouse_ghost_dream",
      "shares": 3
   }
});

由于这是由< script> 标签,函数 jQuery171022388557461090386_1332329918803 被调用,传递解析的JSON作为参数。解析的JSON然后传递给您在 jQuery.getJSON 中定义的函数。

Since this is included by the <script> tag, a function jQuery171022388557461090386_1332329918803 is called, passing the parsed JSON as an argument. The parsed JSON is then passed to the function which you defined in jQuery.getJSON.

这篇关于确切的字符串getJSON和callback =?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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