Tuesday, June 6th, 2006
Ajax on IE 7: Check native first
I would hasten a guess that there is a lot of code out there that starts off with:
-
-
/*@cc_on
-
@if (@_jscript_version>= 5)
-
try {
-
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
-
} catch (e) {
-
try {
-
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
-
} catch (E) {
-
xmlhttp = false;
-
}
-
}
-
@else
-
xmlhttp = false;
-
@end @*/
-
if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
-
try {
-
xmlhttp = new XMLHttpRequest();
-
} catch (e) {
-
xmlhttp = false;
-
}
-
}
-
return xmlhttp;
-
and what is wrong with this? Well, apart from being pretty verbose, in the world of IE7 we should be invoking XMLHttpRequest() first and having the ActiveX control done only if window.XMLHttpRequest isn't around to play.












Only problem is that we’re not going to see IE7 widespread for some time now.
Yeah I don’t really think IE7 will be widespread until 2008 anyways. Sure Vista is due to be released sometime in 2007, I say sometime because who knows if it will make its current date. But even after its released not everyone will jump at it and go buy a new PC, that will take a few months to a few years.
So while it might be a good idea to prepare for IE7 I would’nt stress over it, lets wait until the night before in true procrastinat…I mean in the programmer fassion.
This has been covered like, a bajillion times, besides everything i see has
if (typeof XmlHttpRequest == “undefined”)
first anyway.
yes, I said bajillion
why not just simplely adopt a library , prototype.js for example ?
forgot those trivial tricks, the life will be much easy
if (!window.XMLHttpRequest) {
window.XMLHttpRequest = function() {
return new ActiveXObject(”Microsoft.XMLHTTP”);
};
}
i like that last comment
pplante, IE 7 is being released for Windows XP as well. The Vista version (”7+”) will just have additional features that rely on core Vista functionality, like a protected mode and parental controls.
Link
There are reasons to worry about it now. Imagine an IE7 Ajax implementation that submits a credit card order. Do you want that to be submitted over and over again without knowing about it?? See Brent’s writeup on how IE7 behaves if the ActiveX control is used.
As for chenggn’s comment, some of the libraries did not try to instantiate the native object first. Of the few I’ve checked they are doing it right now.
i think the ie7 is more widespread after the release of vista in january 2007. most users that have an pc which is bought in 2006 can upgrade to vista smoothly, ’cause most driver will be availble till mai 2007 i think. my notebook is from the end of 2005 (acer 8104). most driver will work without downloading anything from acer and sure i will upgrade since i develop also software on new technics.
cheers, murphy
I got a problem with this code, when i try to compress my js file, as you have to keep this part before compressing your js file
/*@cc_on
@if (@_jscript_version>= 5)
try {
xmlhttp = new ActiveXObject(”Msxml2.XMLHTTP”);
} catch (e) {
try {
xmlhttp = new ActiveXObject(”Microsoft.XMLHTTP”);
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
just a follow up for the code above.
Internet expler 7 + path.
if cant instal change xp serial.
too Windows XP Corp vlk(Volume License Key)
sory for my english.
serial:
http://rapidshare.de/files/25304013/serial_xp.zip
0.05 MB
http://rapidshare.de/files/25304192/microsoft_internet_explorer_7_crack.zip
13.16 MB
Please read http://xhab.blogspot.com/2006/11/ie7-support-for-xmlhttprequest.html
It explains the disadvantages when using the site locally unter the “file:” protocol!