Ajax XML response parsing raises error on empty response body in jQuery 1.1.4
The 1.1.4 release adds error checking when it parses an XML response
to an Ajax request, by checking for a "parsererror" tag as the root
tag of the parsed data (which is returned by the browser when the XML
is malformed):
if ( xml && data.documentElement.tagName == "parsererror" )
throw "parsererror";
Unfortunately, the browser considers a blank response body to be
malformed XML, so when an application returns a blank body to indicate
success (Rails, for example, uses this convention to indicate
successful PUT and DELETE actions), the error callback is triggered
instead of the success callback.
This change, therefore, breaks existing APIs that use blank responses
to indicate success. I can't think of a use case where this behavior
would be desirable, so I've come up with a patch that skips throwing
an error for XML responses if the response body is blank:
if ( xml && r.responseText.match(/\S/) && data.documentElement.tagName
== "parsererror" )
throw "parsererror";
patch here: http://dev.jquery.com/ticket/1541