#207 √ duplicate
Adam Nielsen

Ajax.Request IE responds with 1223 instead of 204

Reported by Adam Nielsen | July 7th, 2008 @ 09:11 AM | in 1.6.1

If you use Ajax.Request to send off a request (in my case a POST) to a server, and the server responds with HTTP 204 No Content (success but with no data returned) then under Firefox it works fine and the onSuccess method is called, but under Internet Explorer it fails with the response code 1223.

This is because there is a known issue in IE where it returns 1223 in response to a HTTP 204 code. I think a workaround should be implemented in Prototype to correctly call onSuccess (or on204) even under IE, so the behaviour is uniform across all browsers.

There seems to be some discussion on the list archives about 1223 also being returned in some error conditions, so I'm not sure if any trickery might be needed to correctly determine the situation.

This seems to be a known issue: http://www.mail-archive.com/jquery-en@googlegroups.com/msg13093.html

Comments and changes to this ticket

  • John-David Dalton

    John-David Dalton July 7th, 2008 @ 03:42 PM

    • → Tag changed from “ajax.request ie7” to “ajax.request ie7 needs_patch needs_tests”
    • → Milestone changed from “” to “1.6.1”
    • → State changed from “new” to “bug”
    • → Title changed from “Ajax.Request considers HTTP 204 a failure under IE only” to “Ajax.Request IE responds with 1223 instead of 204”
    • → Assigned user changed from “” to “Tobie Langel”
  • Adam Nielsen

    Adam Nielsen July 8th, 2008 @ 02:35 AM

    Here is a change to the getStatus() function which fixes the problem for me. I only have IE7 available to test with, so I don't know whether the userAgent condition needs to be changed to capture other versions as well - but it will certainly fix the problem for IE7 users.

      getStatus: function() {
        try {
          if (navigator.userAgent.match(/MSIE 7.0/) && this.transport.status == 1223)
            return 204; // Special case where IE7 returns 1223 for HTTP 204 response
          else
            return this.transport.status || 0;
        } catch (e) { return 0 }
      },
    
  • John-David Dalton

    John-David Dalton July 8th, 2008 @ 04:22 AM

    I think we can do this without a browser sniff.

    Here is how jQuery handles it:

    
      // Determines if an XMLHttpRequest was successful or not
      httpSuccess: function( r ) {
        try {
          // IE error sometimes returns 1223 when it should be 204 so treat it as success, see \#1450
          return !r.status && location.protocol == "file:" ||
            ( r.status >= 200 && r.status < 300 ) || r.status == 304 || r.status == 1223 ||
            jQuery.browser.safari && r.status == undefined;
        } catch(e){}
        return false;
      },
    
  • Adam Nielsen

    Adam Nielsen July 8th, 2008 @ 09:25 AM

    That could be fine, but you would probably want to apply the change to the getStatus() function, otherwise getStatus() will return 204 on FF and 1223 on IE. Likewise fudging the return value of getStatus() should make on204() work correctly.

    The only thing that makes me wonder is this post from the prototype mailing list which seems to indicate 1223 is actually a valid error code.

    Having said that perhaps misreporting an infrequent error is better than constantly misreporting a successful request as a failure.

      getStatus: function() {
        try {
          if (this.transport.status == 1223)
            return 204; // Special case where IE7 returns 1223 for HTTP 204 response
          else
            return this.transport.status || 0;
        } catch (e) { return 0 }
      },
    
  • John-David Dalton

    John-David Dalton July 8th, 2008 @ 02:24 PM

    Ya I was just showing you how they handle it without a sniff.

  • Adam Nielsen

    Adam Nielsen July 9th, 2008 @ 01:55 AM

    Ah ok, fair enough. I only put the browser sniff in there in case another browser really does return that code as a legitimate error, but I guess that's probably not too likely anyway.

  • John-David Dalton

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket