Forum Moderators: open
Microsoft has release several versions of MSXML, but only 2 of those versions (6.0 and 3.0) should be used. According to Microsoft [blogs.msdn.com], 6.0 has the best security, performance, reliability, and W3C conformance, and 3.0 is the preferred "fallback". So, we can now define our function which will return an instance of an XMLHttpRequest object (or the ActiveXObject equivalent for IE6):
/**
* Gets an XMLHttpRequest. For Internet Explorer 6, attempts to use MSXML 6.0,
* then falls back to MXSML 3.0.
* Returns null if the object could not be created.
* @return {XMLHttpRequest or equivalent ActiveXObject}
*/
function getXHR() {
if (window.XMLHttpRequest) {
// Chrome, Firefox, IE7+, Opera, Safari
return new XMLHttpRequest();
}
// IE6
try {
// The latest stable version. It has the best security, performance,
// reliability, and W3C conformance. Ships with Vista, and available
// with other OS's via downloads and updates.
return new ActiveXObject('MSXML2.XMLHTTP.6.0');
} catch (e) {
try {
// The fallback.
return new ActiveXObject('MSXML2.XMLHTTP.3.0');
} catch (e) {
alert('This browser is not AJAX enabled.');
return null;
}
}
}
/**
* Gets an XMLHttpRequest. For Internet Explorer 6, attempts to use MXSML 3.0.
* @return {XMLHttpRequest or equivalent ActiveXObject}
*/
function getXHR() {
return window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
}
function getXHR() {
return window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP.3.0');
}