我正在尝试使这项工作,但我不明白为什么总是返回“请求失败”? json似乎是有效的(我知道jQuery对此严格),也许是因为httpS?
var geo_url = "https://spapi.cdnspstr.com/api/get_geo_ip";
var jqxhr = $.getJSON(geo_url, {
format: "json"
})
.done(function (json_data) {
alert("currency: " + json_data.data.currency);
})
.fail(function() {
alert("Request Failed");
});
如果你想从不同的域访问一个文件,然后您的[*同源政策*](http://www.w3.org/Security/wiki/Same_Origin_Policy)的主题。如果服务器不启用CORS,则无法通过Ajax加载文件。 –
我能够使用jsonp发出请求,它允许跨域JSON请求。 http://jsfiddle.net/p2bra/ –
Thx很多,作品完美... – NicoF