IE7, xmlhttprequest, and 1223 status code
I'm working on a program that is fairly Ajax heavy right now. Several of the JS routines need to call for XML from the server, and when there is no data to parse I'm sending a 204 header (no content) so that the JS can know there's no data without having to parse the XML.
But I've found a significant issue. IE7 is changing my 204 header into a 1223 header so the on204: line (I'm using ProtoType JS), isn't catching it. I added an on1223: catch, which works, but seems horribly inefficient.
The only solutions I've found usually involve putting in another on1223: catch and running the same code. But I think I've found a better way. You'll still have to put in on1223:, but it'll run the on204 code without needing to duplicate it.
-
on204: function(req)
-
{
-
// Do whatever you need to do with req
-
}
Then, add this to the Ajax call.
-
on1223: function(req)
-
{
-
req.reqeust.options.on204();
-
}
So the whole thing will look something like this, although you'll have to insert some of your own code to have it actually do something.
-
new Ajax.Request('uri-of-the-request.php',
-
{
-
method: 'post',
-
parameters: 'action=whatever&value2=value2',
-
onSuccess: function(req)
-
{
-
// Do whatever you need to do if it returns full XML
-
},
-
on204: function(req)
-
{
-
// Do whatever you need to do if the XML is empty
-
},
-
on1223: function(req)
-
{
-
// Call the on204 function
-
req.request.options.on204();
-
},
-
onFailure: function(req)
-
{
-
// Do whatever you need to do if the call failed
-
}
-
});
And it looks like this issue is in the Prototype bugs list.
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.