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数据,我还没有意识到这一点。所以我的问题解决了。