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);
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
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