Visit Mozilla.org

Using Web Standards in your Web Pages:Using XMLHttpRequest

From MDC


Microsoft first introduced the XMLHttpRequest object in Internet Explorer 5.0 as an ActiveX control. However, in IE7 and other browsers XMLHttpRequest is a native scripting object. Thus, the most widely-supported way of including an XMLHttpRequest is to use the native object if possible, and fall back on the ActiveX control, like this:

if (window.XMLHttpRequest)
{
    //Firefox, Opera, IE7, and other browsers will use the native object
    var request = new XMLHttpRequest();
}
else
{
    //IE 5 and 6 will use the ActiveX control
    var request = new ActiveXObject("Microsoft.XMLHTTP");
}

If support for IE 5 and 6 is not a concern, then this next approach will work fine and is much more concise:

var request = new XMLHttpRequest()

More on XMLHttpRequest: