Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to solve json error : SyntaxError: missing ; before statement {"products":[{"title":"xyz","id":1718,"created_at?

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??

like image 994
Sanjay Rathod Avatar asked Nov 21 '25 12:11

Sanjay Rathod


1 Answers

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).

like image 149
Quentin Avatar answered Nov 24 '25 00:11

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!