的getJSON意外的标记错误标记、意外、错误、getJSON

2023-09-10 20:40:13 作者:帅到炸

我想从美国地质调查局的地震数据,我不断收到错误:

I'm trying to get earthquake data from USGS and I keep getting the error:

未捕获的SyntaxError:意外的标记:

我尝试$就与JSONP格式,我不断收到同样的问题。我想没有回调在我的网址的结尾为好,在这种情况下,我得到的错误:

I tried $.ajax with jsonp format and I keep getting the same issue. I tried without callback at the end of my url as well, in that case I get the error:

MLHtt prequest无法加载 HTTP ://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson 。产地 http://people.oregonstate.edu 不受访问控制 - 允许 - 产地允许的。

MLHttpRequest cannot load http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson. Origin http://people.oregonstate.edu is not allowed by Access-Control-Allow-Origin.

$.getJSON(
   "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson&callback=?",
    function(data) {
       console.log(data);
    }
 );

有人可以帮助我如何获得数据或者东西比其他的jQuery,如果这是不可能这样的。

can someone help me out how to get the data or perhaps something other than jQuery if it is not possible this way.

推荐答案

最简单的方法来解决它会告诉你想JSONP的服务,然后使用由服务提供的回调。

the easiest way to get around it would be to tell the service you want jsonp, then use the callback provided by the service.

window.eqfeed_callback = function(data){
    console.log(data);
};
//$.getScript("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojsonp");
var s = document.createElement("script");
s.src = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojsonp";
document.getElementsByTagName("head")[0].appendChild(s);