[ACCEPTED]-jquery ajax 200 OK JSON.ParseError-webmethod

Accepted answer
Score: 23

Try to remove contentType and dataType from Ajax parameters 1 and let them be identified automatically

Score: 1

Had the same problem with AJAX's 'post' command.

Sent 7 a JSON post request, got a 200 OK repsponse 6 but textStatus was parseerror and errorThrown was 5 SyntaxError: JSON.parse: unexpected character.

This is my JS code:

$.post(url, JSON.stringify(reportVarsJson), function(response) {}, 'json')
.fail(function(jqXHR, textStatus, errorThrown) {
    alert('Error saving report request variables:\n\n' + jqXHR.responseText);

The problem turned out 4 to be that my server view (Django) returned 3 an empty response which was not a JSON response.

I 2 changed my server view to return an empty 1 json response and everything works well!

Score: 0

Not sure about [WebMethod], but it seems 7 that the problem is there, and it is related 6 with the output of that method. It has to 5 be a well formed JSON for the ajax method 4 to work. So what I would do is to check 3 call that in a separate window to see the 2 respons and to use something like http://jsonlint.com/ to make 1 sure it is well formed.

More Related questions