简体   繁体   English

未捕获的SyntaxError:意外的令牌:ajax调用

[英]Uncaught SyntaxError: Unexpected token : ajax call

So I'm trying to query the below json feed, however I keep getting the error in the topic. 所以我试图查询下面的json提要,但是我不断收到该主题中的错误。 I've searched around this site for possible answers however none that I've come across have worked so far. 我在该站点附近搜索了可能的答案,但是到目前为止,我所遇到的任何方法都没有奏效。 Commented out datatype and jsonp, jsonpCallback isnt it either, either is data, I've made sure that it validats via http://jsonformatter.curiousconcept.com/ and it does. 注释掉数据类型和jsonp,jsonpCallback也不是它,或者是数据,我已经确保它通过http://jsonformatter.curiousconcept.com/进行验证 ,并且确实有效。 I really dont know. 我真的不知道。

 $.ajax({                                                                                                                                                                                                        
            type: 'GET',                                                                                             
            url: 'http://raidbots.com/json/playerdata/us/mannoroth/usiris', 
            cache:true,                                                                                              
            dataType: 'jsonp',
            data: { 
                format: 'json',
            },                                                                                                       
            success: ranks,
            jsonpCallback:'callbackName',                                                                            
            error: function(data) { console.log(data); },
            jsonp: false,                                                                                                                                                
        });



 function callbackName(data){
   console.log("jsonpCallback");
 }

 var ranks = function(data) {
  console.log(data);
 }

Thank you -Art 谢谢-艺术

The error is in your JSONp data because it's just JSON and not JSONp. 错误出在您的JSONp数据中,因为它只是JSON,而不是JSONp。 JSONp requires the document to be valid JavaScript containing a function call. JSONp要求文档是包含函数调用的有效JavaScript。

If they don't support jsonp you need to use a proxy script (eg a php script on your server that retrieves the document) or ask them to send CORS headers so you can use a normal non-JSONp AJAX call to retrieve the data directly. 如果他们不支持jsonp,则需要使用代理脚本(例如,服务器上检索文档的php脚本)或要求他们发送CORS标头,以便您可以使用常规的非JSONp AJAX调用来直接检索数据。

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

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