Quote:
Originally Posted by Old Pedant
As Felgall said.
One better way (and there are others, but this works for me) is:
Code:
function createRequestObject() {
return ( XMLHttpRequest != null )
? new XMLHttpRequest( )
: new ActiveXObject("Microsoft.XMLHTTP");
}
Another seemingly popular way:
Code:
function createRequestObject()
{
try {
return new XMLHttpRequest();
} catch ( ignored ) { }
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch ( oops ) {
return null;
}
}
|
Of course with IE6 being dead you can even drop the activeX reference completely and just use
new XMLHttpRequest() since all the browsers people current use support it.