我习惯使用 jQuery,它非常适合:
$.ajax({
method: "GET",
url: "someURL",
dataType: "jsonp",
jsonp: 'jsonp',
success: function (msg) {},
error: function (msg) {}
});
** 注意:当我省略jsonp: 'jsonp'时,控制台中会显示此错误:
Uncaught SyntaxError: Unexpected token :
阅读 Mootools 文档后我尝试的方法:
试图:
new Request.JSONP({
url: "someURL",
onComplete: function (msg) {},
onFailure: function (msg) {}
}).get();
错误:
Uncaught TypeError: undefined is not a function
它显示 Response.JSONP 不是函数。当我尝试使用 JSON 时:
试图:
new Request.JSON({
url: "someURL",
onComplete: function (msg) {},
onFailure: function (msg) {}
}).get();
错误:
XMLHttpRequest cannot load http://www.theirsite.com. Origin http://yoursite.com is not allowed by Access-Control-Allow-Origin.
这是使用 Ajax 的跨域访问问题,这就是我使用 JSONP 的原因。
我很困惑
Uncaught TypeError: undefined is not a function
错误,我不明白为什么它适用于 jQuery。
任何见解表示赞赏