This is the code to create a cross-browser Ajax object in javascript.
- Code: Select all
if (window.XMLHttpRequest) // Mozilla, Safari,...
{
objXHR = new XMLHttpRequest( );
if (objXHR.overrideMimeType)
{
objXHR.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) // IE
{
try
{
objXHR = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
objXHR = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
throw e;
}
}
}
if (!objXHR)
{
alert('Giving up :( Cannot create an XMLHTTP instance');
return null;
}
return objXHR;