Alistair Miles

Category: http

AJAX, Internet Explorer, MIME Types and HTTP Proxies

This is a followup to the post I wrote regarding the “object required” error I ran into when testing an AJAX application in Internet Explorer … I’ve now got to the bottom of the mystery!

The immediate problem was indeed that my server application was, under certain circumstances, returning an HTTP response that did not have a “Content-Type” header set to “text/xml”. If the header is not set thus, Internet Explorer will not instantiate the responseXML member of the XMLHttpRequest object, leading to the “object required” error when you try to access members of the expected (but non-existent) XML response document.

The bug was ultimately within the server application, which failed to send the correct “Content-Type” HTTP header. I eventually found that the bug was in fact within a Filter that encoded the content of the HTTP response using GZIP if the client indicated that it could accept such an encoding. The bug only materialised when the client did not indicate that it could accept a GZIP encoding, otherwise the correct HTTP headers were sent. Furthermore, I found that IE6 indicates that it can accept GZIP encoding when connected directly to the internet, but when making requests through an HTTP proxy it does not issue an “Accept-Encoding” header at all. This was the reason why, when I fiddled with the HTTP proxy settings in IE, the bug sometimes disappeared.

Btw I used ieHTTPHeaders to inspect HTTP traffic to and from Internet Explorer, and LiveHTTPHeaders to inspect HTTP traffic to and from Mozilla.

Advertisements

Internet Explorer AJAX Gotcha: “Object Required” Error

I came across this AJAX gotcha in IE yesterday … when I ran my brand new AJAX application in Internet Explorer 6.0 on my own computer, it worked fine, but when others ran it on their computers using the same version of IE, they got an “Object Required” javascript error.

I discovered (eventually) that, if the response to the XML HTTP request does not have Content-Type “text/xml”, then MSXML does not instantiate the responseXML member of the XMLHTTPRequest object, although it will instantiate the responseText member – see the MSXML2 API spec. Once I had fixed the server-side code to return the correct Content-Type, it worked. As an item of good-practice, you should probably include an “Accept: text/xml” header in the request, to be on the safe side.

Read the rest of this entry »