的getJSON意外的标记错误 [英] getJSON unexpected token error

查看:367
本文介绍了的getJSON意外的标记错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

这篇关于的getJSON意外的标记错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆