17

I'm submitting a form using an ajax request (POST method), and checking the HTTP status code on the response to see if it was successful or not.

It works fine on Firefox, but of course doesn't on MSIE-8. The submission actually works fine, I can check my server and confirm that the submission worked and the server responded with a status code of 204. Again, firefox correctly gives me the status code of 204 from the request object, but IE gives a status code of 1223.

Any ideas how I can get an accurate status code in MSIE? The code that submits the form and checks the response is below.

    var req = new XMLHttpRequest();
    req.open("POST", "p.php?i=" + self.__isid, true);
    //Send the proper header information along with the request
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    req.setRequestHeader("Content-length", formdata.length);
    req.setRequestHeader("Connection", "close");

    req.onreadystatechange = function()
    {
        if(req.readyState == 4)
        {
            if(req.status == 204 || req.status == 200)
            {
                //Success. Update the feed.
                self.__postFeed.update();
                self.__form.reset();
            }
            else
            {
                //TODO: Better error handling.
                alert("Error submitting post:\n" + req.responseText);
            }
        }
    }
    req.send(formdata);
  • Did a little more experimenting: if I have the server return a status code of 200, then MSIE works fine. But if it's 204, it gives me that crazy 1223 status. I'd really like to stick with the 204 because that's the most appropriate response, so if anyone can help figure out how to get that, I'd appreciate it. – brianmearns Apr 6 '12 at 14:31
34

XMLHTTPRequest implementation in MSXML HTTP (at least in IE 8.0 on Windows XP SP3+) does not handle HTTP responses with status code 204 (No Content) properly; the `status' property has the value 1223.

This is a known bug and most of the javascript based frameworks handle this situation and normalizes 1223 to 204 in IE

So the solution to your problem would be like this

// Normalize IE's response to HTTP 204 when Win error 1223.
status : (conn.status == 1223) ? 204 : conn.status,
// Normalize IE's statusText to "No Content" instead of "Unknown".
statusText : (conn.status == 1223) ? "No Content" : conn.statusText

Reference:

dojo - http://trac.dojotoolkit.org/ticket/2418

prototype - https://prototype.lighthouseapp.com/projects/8886/tickets/129-ie-mangles-http-response-status-code-204-to-1223

YUI - http://developer.yahoo.com/yui/docs/connection.js.html (handleTransactionResponse)

JQuery - http://bugs.jquery.com/ticket/1450

ExtJS - http://www.sencha.com/forum/showthread.php?85908-FIXED-732-Ext-doesn-t-normalize-IE-s-crazy-HTTP-status-code-1223

  • Apparently IE drops all response headers in this case too! And apparently it happens in IE9 too... but it's been fixed in IE10. Source: enhanceie.com/ie/bugs.asp (ctrl+F for 1223) – Aseem Kishore Jan 11 '13 at 2:36
  • thanks for update :) good that its been fixed finally, i wonder why they haven't backported fix to IE9 atleast – Saket Patel Jan 11 '13 at 20:14
  • what is not working? and what status code you get in response? – Saket Patel Mar 1 '13 at 19:37
  • 2
    Apparently this also applies to the MSXML2.XMLHTTP60 object for use in VBA/Excel. Thank you. – Joe Feb 23 '18 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.