Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery跨域getJSON ajax_Jquery_Ajax_Json_Cross Domain - Fatal编程技术网

JQuery跨域getJSON ajax

JQuery跨域getJSON ajax,jquery,ajax,json,cross-domain,Jquery,Ajax,Json,Cross Domain,我正在尝试使用此JSONweb服务: 我尝试了以下代码: $.ajax({ url: url, type: 'GET', crossDomain: true, dataType: 'json', jsonp: false, success: function() { alert("Success"); }, error: function() { alert('Failed!'); }}); } 我在chrome中遇到以下错误: XMLH

我正在尝试使用此
JSON
web服务:

我尝试了以下代码:

$.ajax({
    url: url,
    type: 'GET',
    crossDomain: true,
    dataType: 'json',
    jsonp: false,
    success: function() { alert("Success"); },
    error: function() { alert('Failed!'); }});
}
我在chrome中遇到以下错误:

XMLHttpRequest cannot load ...earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_week.geojson. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost' is therefore not allowed access.

我已经看到了将
datatype
更改为
jsonp
的所有建议,但这在我的情况下不起作用,因为此服务不提供
jsonp
数据。
有没有其他方法可以用JavaScript解析这些数据?

你在这里运气不好。您可以设置服务器代理并请求它。看来在同一个域上使用服务器代理是唯一的方法。请参阅此答案,例如“因为此服务不提供
jsonp
数据”-您是否尝试过此url:谢谢大家的帮助。代理方法对我不起作用。但正如Stephan Muller所说,该服务提供jsonp数据,我还没有意识到这一点。所以我的问题解决了。