确切的字符串getJSON和callback =? [英] exact string to getJSON and 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:
- 基本URL: http://graph.facebook.com/?ids=http://legrandj.eu/article/blouse_ghost_dream
- 回调处理程序:
& callback = jQuery171022388557461090386_1332329918803
jQuery替换?
callback =?中使用唯一的临时标识符。 - 破坏破解:
& _ = 133232991983
- Base URL: http://graph.facebook.com/?ids=http://legrandj.eu/article/blouse_ghost_dream
- Callback handler:
&callback=jQuery171022388557461090386_1332329918803
jQuery replaces?
incallback=?
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屋!