Prototype fix for the IE bug where 204 => 1223

I ran into a strange problem when working on a new polling Ajax feature for one of our projects. Before I get into the issue, I'll set up the context.

I don't like the brute force approach of the PeriodicalUpdater, so instead I wanted to roll my own solution that utilized proper HTTP response codes to manage browser behavior. In particular, if there is nothing to report from the server, I can use the 204 - No Content (See W3C Documents) response code. In this way, I can simply use the onSuccess callback to schedule another check after an interval if there is no response body.

This worked wonderfully in Firefox and Safari, as expected. Of course, on IE, instead of calling onSuccess, it seemed to be calling onError, even though no error occurred. After displaying the status code in the error message, I found that IE was reporting the status code not as 204, but as 1223. As far as I can tell, there is no reason for this. I have found that other JS libraries have addressed the issue, so I went into prototype.js and solved the problem in the code.

I've submitted a patch to the Prototype team through their Lighthouse page, and the fix should get into the 1.6.0.3 release. If you are impatient and need the fix now, or are interested in getting into prototype hacking, here is the simple change:

prototype.js:199

 success: function() {
    var status = this.getStatus();
	// accept 1223 as a successful status, IE interprets 204 as 1223
    return (!status && this._allowStatusZero) || (status >= 200 && status < 300) || (status == 1223);
  },

Posted by Adeh Tue, 03 Jun 2008 22:05:00 GMT