简体   繁体   中英

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. 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. 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 requires the document to be valid JavaScript containing a function call.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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