i have some code in ajax call like below
$.ajax({
url: query_string,
cache: true,
type: 'GET',
async: false, // must be set to false
success: function (data, success) {
alert(jquery.parseJSON(data));
alert('success');
//alert(data);
//alert(success);
},
dataType: 'jsonp',
error :function( jqxhr, textStatus, error ) {
var err = textStatus + ', ' + error;
alert(err);
},
complete: function (jqxhr, textStatus ){
//alert( "complete: " + JSON.stringify(jqxhr)+" "+ textStatus );
}
});
when i run this code into firefox with fire bug. firebug shows response in perect json format but shows following error in firebug
SyntaxError: missing ; before statement
{"products":[{"title":"xyz","id":1718,"created_at
so how can i solve it??
You are telling jQuery to process the response as JSONP:
dataType: 'jsonp'
… but the response is JSON, not JSONP.
Get rid of the p or get rid of the dataType line entirely and let jQuery determine the data type from the Content-Type of the response (which should be application/json).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With