Ajax Error: 200 Response Code

Advertisement

I use the jQuery Form plugin to manage a form submission with Ajax:

 $('.login-form').ajaxForm({ dataType: 'json', success: function(data){ console.log('Success!'); console.log(data); }, error: function(data){ console.log('There was an error:'); console.log(data); } }) 

After submitting, the ajax returns an error with a status of "200". This is the response formatted by JSON:

 { "success": false, "heading": "The following errors were encountered", "message": " 
  • The existing username and / or password you submitted are not valid
" }

I ran it through jsonlint.com, and it came back as valid.

On the Chrome Network tab, the response is returned as the application/json type.

So why did Ajax return "error" rather than "success"?

jQuery 1.9.1

The answer

The value of the JSON message key had a line break inside, which for some reason caused an error:

 { "success": false, "heading": "The following errors were encountered", "message": " 
  • The existing username and / or password you submitted are not valid
" }

I would not think that line breaks in a chain matter, but I guess they do ...