Search code examples
javascriptjqueryajaxjsonjsonp

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


Solution

  • 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 (e.g. 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.