jQuery JSON response always triggers a ParseError jQuery JSON response always triggers a ParseError jquery jquery

jQuery JSON response always triggers a ParseError


Maybe I'm misunderstanding, but couldn't you set the dataType to text and JSON.parse() the returned data?

success: function(data) {    data = JSON.parse(data);    // process data},

Edited to add generally agreed upon solution (previously a comment only):

I just took a look at api.jquery.com/jQuery.ajax and it looks like with jQuery 1.5 you can do a type conversion of sorts. "multiple, space-separated values: As of jQuery 1.5, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use "text xml" for the dataType." Maybe you can try "text json".


I got the same error as soon as I upgraded to jQuery 1.5. It turns out that my problem is because I'm also using the jquery validation plugin, which is not compatible with jQuery 1.5. If I remove the jquery validation plugin, $.ajax() with dataType json works fine.

More information about the jquery validation plugin incompatibility here:http://bugs.jquery.com/ticket/8118


I also got "parsererror jQueryNNNN_NNN was not called" (using jsonp and jQuery 1.7.2)The reason was that one of the values in the returned json structure contained newlines.Hope this helps someone.