简体   繁体   English

未捕获到的SyntaxError:意外令牌:

[英]Uncaught SyntaxError: Unexpected token :

Forgive me, I'm completely new to using JSON/JSONP/AJAX and have been researching this extensively for the last 24 hours and can't figure it out. 请原谅,我是使用JSON / JSONP / AJAX的新手,并且在过去的24小时内对此进行了广泛的研究,无法解决。 Your help would be appreciated. 您的帮助将不胜感激。

I am trying to get information out of a simple JSON file from another server and display it very plainly on my website. 我正在尝试从另一台服务器的简单JSON文件中获取信息,并将其非常清楚地显示在我的网站上。

The JSON file I'm trying to pull information from: http://evewho.com/api.php?type=corplist&id=98224089 我正尝试从以下位置获取信息的JSON文件: http : //evewho.com/api.php?type=corplist&id=98224089

I'm trying to display just the character names from that JSON here inside the #characters div: http://anomaly47.com/jsonp_test.html 我试图在#characters div中仅显示来自该JSON的字符名称: http ://anomaly47.com/jsonp_test.html

So far I am just trying to connect and see the objects information using the following code: 到目前为止,我只是尝试使用以下代码连接并查看对象信息:

$(document).ready(function() {

var url = 'http://evewho.com/api.php?type=corplist&id=98224089&callback=?';

  $.getJSON(url, null, function(data){
        console.log(data);
      }
  )

});

I keep getting the following error in the console: 我在控制台中不断收到以下错误:

Uncaught SyntaxError: Unexpected token : api.php?type=corplist&id=98224089&callback=jQuery1111010067848535254598_1425072137785&_=14250721377…:1 未捕获到的SyntaxError:意外令牌:api.php?type = corplist&id = 98224089&callback = jQuery1111010067848535254598_1425072137785&_ = 14250721377…:1

I'm not sure what I'm doing wrong here. 我不确定我在做什么错。

Thanks again! 再次感谢!

Not all API's that serve json are accessible using ajax. 并非所有使用json的API都可以使用ajax访问。

Your API is not returning jsonp data format and is not CORS enabled. 您的API未返回jsonp数据格式,并且未启用CORS。

If it is your site, and you are making request from the same domain, remove the &callback=? 如果它是您的站点,并且您正在同一域中发出请求,请删除&callback=? from url since this tells jQuery that request is for jsonp . 从url开始,因为这告诉jQuery请求是jsonp

If it is a cross domain request you will need to set up a proxy on your server to retrieve the data and make your ajax call to your proxy script 如果是跨域请求,则需要在服务器上设置代理以检索数据并对代理脚本进行ajax调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM