Skip to content
Advertisement

jquery ajax Uncaught SyntaxError: Unexpected token : while calling an api

I am trying to get a json response from the comicvine api but am getting the following error. comicvine.gamespot.com/:1 Uncaught SyntaxError: Unexpected token :

I see my json result, formatted, in the response body but am getting the console error above.

JavaScript

Advertisement

Answer

You need to set format=jsonp not json

the jsonp callback parameter name needs to be json_callback according to comicvine.gamespot.com – I found this out by going to url https://comicvine.gamespot.com/api/characters/?api_key=[your api key]&filter=gender:male,name:hawkeye&format=jsonp in the browser, and it told me what was missing – very friendly API – the response had an error value

JavaScript

and no need for callback=? in the url – seeing as jquery adds the callback parameter and it isn’t named callback

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement