This is just a little note for anyone doing xmlHttp work. I just encountered this situation this morning. As most web developers know IE7 introduces support for the native scriptable XMLHttpRequest object. The big advantage here is that ActiveX is no longer necessary to use ajax applications on IE. One thing I did note is that there is a slight difference in their support for the XMLHttpRequest object. Take the following code:
// Mozilla/Safari/IE7+
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.overrideMimeType('text/xml');
}
// IE6-
else if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttpReq.open('POST', strURL, true);
-
// Mozilla/Safari/IE7+
-
if (window.XMLHttpRequest) {
-
xmlHttpReq = new XMLHttpRequest();
-
xmlHttpReq.overrideMimeType(‘text/xml’);
-
}
-
// IE6-
-
else if (window.ActiveXObject) {
-
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
xmlHttpReq.open(‘POST’, strURL, true);
That seems to break for me on IE7. A little experimentation shows that it doesn’t support the overrideMimeType() method. A simple fix for this is to simply check before invoking it as follows:
// Mozilla/Safari/IE7+
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
if(xmlHttpReq.overrideMimeType){
xmlHttpReq.overrideMimeType('text/xml');
}
}
// IE6-
else if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttpReq.open('POST', strURL, true);
-
// Mozilla/Safari/IE7+
-
if (window.XMLHttpRequest) {
-
xmlHttpReq = new XMLHttpRequest();
-
if(xmlHttpReq.overrideMimeType){
-
xmlHttpReq.overrideMimeType(‘text/xml’);
-
}
-
}
-
// IE6-
-
else if (window.ActiveXObject) {
-
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
xmlHttpReq.open(‘POST’, strURL, true);
This is just FYI for anyone who happens to encounter this error. It’s a simple fix. This somewhat goes without saying, but make sure your request returns from the server as text/xml or you’ll likely still encounter issues.