JSONP无法用于跨域AJAX

问题描述 投票:1回答:1

我已经查看了所有跨域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);
    }
});
javascript jquery ajax jsonp
1个回答
1
投票

您那里有一个小错字:

…
dataType: "jsonp", // dataType instead of datatype
…

JavaScript变量和对象属性区分大小写。

© www.soinside.com 2019 - 2024. All rights reserved.