What is the best method for creating an XMLHttpRequest object?
It should work in all capable browsers.
This is what I use, it works fine for me:
function request()
{
try
{
try
{
return new ActiveXObject("Microsoft.XMLHTTP")
}
catch( e )
{
return new ActiveXObject("Msxml2.XMLHTTP")
}
}
catch(e)
{
return new XMLHttpRequest()
}
}
Use jQuery (or a similar JavaScript library). It takes care of the cross-browser compatibility issues of things like making Ajax calls.
For example, using the jQuery Ajax call:
$.ajax({
url: 'document.xml',
type: 'GET',
dataType: 'xml',
timeout: 1000,
error: function(){
alert('Error loading XML document');
},
success: function(xml){
// do something with xml
}
});
Use XMLHttpRequest.js - Standard-compliant cross-browser XMLHttpRequest object implementation and work with the object in a standard (W3C) way