jQuery ajax:error runs even if the response is OK 200

If the server returns something that isn't valid JSON, such as a single space, jQuery will generate a parse error and consider it a failed request even if the status code is 200.

As of jQuery 1.9 a completely empty response is considered a failed request when the type is set to JSON since an empty string is invalid JSON. See http://jquery.com/upgrade-guide/1.9/#jquery-ajax-returning-a-json-result-of-an-empty-string.


  1. Check that $.ajax's datatype is set to jsonp

  2. Try to return {email:"[email protected]"}


JSON.parse('') throws an error. To me, that is stupid, it should return undefined. I added this code to my app

#HACK JSON.parse('') should return undefined, not throw an error
_parse = JSON.parse
JSON.parse = (str) =>
  unless str == ''
    _parse.apply JSON, arguments

or for u poor people not using coffeescript ( untested )

//HACK JSON.parse('') should return undefined, not throw an error
var _parse = JSON.parse
JSON.parse = function(str) {
  if (str !== '')
    return _parse.apply(JSON, arguments);
  else
    return undefined;
}