When an XmlHttpRequest object makes a request to a server, it stores the server’s response in the “status” and “statusText” fields. “Status” holds the status code, while “statusText” holds the reason phrase, as defined in the HTTP/1.1 specs.

Recently I found that the status and statusText returned by the XmlHttpRequest object does’t always match what actually comes from the server. To test this out, I created a page that receives various XmlHttpRequest responses and compares them to the expected values. You can try it out in your own browser here:

For the most part, browsers are compliant, with a few grammatical differences in statusText. Here are some of the major discrepancies:

408 Request TimeoutFirefox throws a javascript error when accessing “status” and “statusText” for this particular status code.

Internet Explorer 6
204 No Contentstatus = 1223
statusText = Unknown
301 Moved Permanently
302 Found
303 See Other
307 Temporary Redirect
In all these cases, IE returns:
status = 12150
statusText = Unknown

Safari 3.0.4
Although Safari returns the correct status codes for most instances, the statusText is “OK” for ALL status codes! Browsing through the source code for WebKit, it looks like this is a known issue; there is a comment that says “FIXME: it would be nice to have a way to get the real status text eventually“.

Opera 9.25
204 No Content
304 Not Modified
504 Gateway Time-out
Returns status = 0 with no statusText
401 UnauthorizedReturns incorrect status 403
407 Proxy Authentication RequiredReturns incorrect status 403
417 Expectation FailedReturns nothing

I’m sure this isn’t an issue for most users, as all the boilerplate XmlHttpRequest code I’ve seen only checks for status ‘200′ (which all browsers return correctly). However as AJAX applications become more complex, this might become more relevant.