サーバーはリクエストURLのパラメータを受け入れないため、URLの余分なパラメータをすべて削除する必要があります。もちろん、サーバーを制御することはできません。
jQuery:
$.ajax({
type: 'GET',
url: 'http://cross-domain.com/the_jsonp_file,
jsonpCallback: 'jsonCallback',
contentType: 'application/json',
cache: 'true',
dataType: 'jsonp',
success: function(json) {
console.log(json);
},
});
JSONPファイル:
jsonCallback({"test": "hello"});
そのAjaxリクエストを送信すると、URLは次のようになります。
http://cross-domain.com/the_jsonp_file?callback=jsonCallback
しかし、私はこれが必要です(パラメーターなしで):
http://cross-domain.com/the_jsonp_file
編集:
これが私の全体的な状況です:
function MyClass(imgs) {
// imgs is array of URLs
this.imgs = imgs;
this.submit = function() {
// button click event triggers this method
this._show();
};
this._show = function() {
var _this = this;
for (var i = 0; i < _this.imgs.length; i++) {
(function($, j) {
$.ajax({
type: 'GET',
url: _this.imgs[j],
jsonp : false,
jsonpCallback: 'jsonCallback',
cache: 'true',
dataType:'jsonp',
success: function(json) {
console.log(_this.imgs[j]);
},
});
})(jQuery, i);
};
};
};
そして、私はこのエラーメッセージを受け取りました:
Uncaught TypeError: Property 'jsonCallback' of object [object Window] is not a function
奇妙なことに、jsonCallbackを正常に呼び出しているリクエストはほとんどありません。