AJAX call and clean JSON but Syntax Error: missing ; before statement AJAX call and clean JSON but Syntax Error: missing ; before statement ajax ajax

AJAX call and clean JSON but Syntax Error: missing ; before statement


JSONP is not JSON. A JSONP response would consist of a JavaScript script containing only a function call (to a pre-defined function) with one argument (which is a JavaScript object literal conforming to JSON syntax).

The response you are getting is JSON, not JSONP so your efforts to handle it as JSONP fail.

Change dataType: 'jsonp' to dataType: 'json' (or remove the line entirely, the server issues the correct content-type so you don't need to override it).

Since your script is running on a different origin to the JSON then you will also need to take steps (most, but not all, of which require that you control the host serving the JSON) to work around the same origin policy.


The error is because it is returning JSON not JSONP.

JSONP is supposed to look like

someCallBackString({ The Object });


Here is the working example

$.ajax({ type: 'GET', url: 'http://xxx.amazonaws.com/file.json', dataType: 'jsonp', jsonpCallback: 'callback', success: function(json){   console.log(json); }});

And you should put callback in the beginning of your file.json like :

callback({"item":{".......