我已经查看了所有跨域 ajax 问题,但仍然无法弄清楚我的 JSONP 请求出了什么问题。我想做的就是使用 JSONP 跨域获取外部页面的内容。不幸的是,Firefox 仍然给出了这个:
跨源请求被阻止:同源策略不允许读取 https://stackoverflow.com/?_=1415036764663 处的远程资源。可以通过将资源移动到同一域或启用 CORS 来解决此问题。
代码:
var url = "http://stackoverflow.com";
$.ajax({
url: url,
type: "GET",
datatype: "jsonp", //allows cross-domain ajax without cors (GET only)
async: true,
cache: false,
timeout: 15000,
success: function(html) {
console.log(html);
}
});
最佳答案
你有一个小错字:
…
dataType: "jsonp", // dataType instead of datatype
…
JavaScript 变量和对象属性区分大小写。
关于javascript - JSONP 不适用于跨域 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26720074/