创建通用XMLHttpRequest对象
function createXmlHttpRequestObject()
{
if (window.XMLHttpRequest)
{ xmlhttp_request = new XMLHttpRequest(); }
else
{ var MSXML=['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
for(var n = 0; n < MSXML.length; n ++)
{
try
{
xmlhttp_request = new ActiveXObject(MSXML[n]);
break;
}
catch(e){}
}
}
}
或
function createXmlHttp()
{
var oXmlHttp = null;
if (window.ActiveXObject) // IE
{
try{oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e){try{oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}catch (e){}}
}
else
{
if (window.XMLHttpRequest) // Mozilla, Safari,
{
oXmlHttp = new XMLHttpRequest();
if (oXmlHttp.overrideMimeType)
{
oXmlHttp.overrideMimeType('text/xml');
}
}
}
if (!oXmlHttp)
{
alert('错误:不能创建 XMLHTTP 实例');
}
return oXmlHttp;
}