它被称为callbackKey
JSONP。 read the doc。
这里的扩展JSONP,我写(改变API PLS)在flickr类:
// the class
Request.flickr = new Class({
Extends: Request.JSONP,
options: {
callbackKey: "jsoncallback",
url: "http://www.flickr.com/services/rest/?",
log: true
},
initialize: function(params, options) {
this.parent(options);
this.options.url = this.options.url + Object.toQueryString(params);
},
success: function(data, script) {
this.parent(data, script);
},
imageURL: function(obj) {
return "http://farm{farm}.static.flickr.com/{server}/{id}_{secret}.jpg".substitute(obj);
}
});
// example on how to use
new Request.flickr({
format: 'json',
api_key: "e7df6c74d2545f55414423463bf99723", // your api here
per_page: 4,
tags: "mountains",
method: "flickr.photos.search"
}, {
onSuccess: function(data) {
target = document.id("action");
var self = this;
data.photos.photo.each(function(el) {
new Asset.image(self.imageURL(el), {
onload: function() {
this.inject(target);
}
});
});
}
}).send();
完全地覆盖这些回调,并通过在外部功能(需要是全球性的):
window.foo = function(data) {
console.log(data);
};
Request.flickr = new Class({
Extends: Request.JSONP,
options: {
url: "http://www.flickr.com/services/rest/?jsoncallback=foo&",
log: true
},
initialize: function(params, options) {
this.parent(options);
this.options.url = this.options.url + Object.toQueryString(params);
},
success: function(data, script) {
this.parent(data, script);
},
imageURL: function(obj) {
return "http://farm{farm}.static.flickr.com/{server}/{id}_{secret}.jpg".substitute(obj);
}
});
// example on how to use
new Request.flickr({
format: 'json',
api_key: "e7df6c74d2545f55414423463bf99723",
// your api here
per_page: 4,
tags: "mountains",
method: "flickr.photos.search"
}).send();
上面的代码将运行函数foo,将JSON对象传递给它。 http://jsfiddle.net/dimitar/DUtff/
感谢您的帮助,我检查你的代码,我看到请求的URL是: HTTP://www.flickr.../ jsoncallback =富&FORMAT = JSON&API_KEY = * =方法flickr.photos .search&callback = Request.JSONP.request_map.request_0 有什么方法可以删除或更改最后一部分? (callback = Request.JSONP.request_map.request_0) 我的问题是,我的函数将在setInterval函数中,并且每次它执行所请求的url更改,如下所示: callback = Request.JSONP.request_map.request_0 callback = Request.JSONP.request_map.request_1 ... n 我不需要更改最后一位 –
然后不要使用Request.JSONP,而是通过Asset.javascript或其他方式编写自己的包装。 Request.JSONP将始终输出它。尽管如此,你可以重构它并让它不能这样做。 –
好的,对于这些建议 –