为了兼容常见的浏览器的话,可以考虑用下边两段代码之一:
function CreateXMLHttp()
{
xmlHttp = false;
if(typeof XMLHttpRequest != 'undefined')
{
var xmlHttp = new XMLHttpRequest();
return xmlHttp;
}else if(window.ActiveXObject)
{
var IEXMLHttpVersion = ["MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
//for Microsoft Internet Explorer
for(var i= 0 ;i < IEXMLHttpVersion.length; i++)
{
try
{
var xmlHttp = new ActiveXObject(IEXMLHttpVersion[i]);
return xmlHttp;
}catch(e)
{
//Do nothing
}
}
}else
{
throw new Error("XMLHttp object could be created.");
}
}
xmlHttp = CreateXMLHttp();
xmlHttp.setRequestHeader("Content-Type","text/xml");
xmlHttp.setRequestHeader("Content-Type","gb2312");
var xmlHttp=null;
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
catch(oc)
{
xmlHttp=null
}
}
if ( !xmlHttp && typeof XMLHttpRequest != "undefined" )
{
xmlHttp = new XMLHttpRequest()
}
Tags -
xmlhttp ,
对象 ,
浏览器 ,
msxml ,
ie ,
firefox
为了兼容常见的浏览器的话,可以考虑用下边两段代码之一:
function CreateXMLHttp()
{
xmlHttp = false;
if(typeof XMLHttpRequest != 'undefined')
{
var xmlHttp = new XMLHttpRequest();
return xmlHttp;
}else if(window.ActiveXObject)
{
var IEXMLHttpVersion = ["MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
//for Microsoft Internet Explorer
for(var i= 0 ;i < IEXMLHttpVersion.length; i++)
{
try
{
var xmlHttp = new ActiveXObject(IEXMLHttpVersion[i]);
return xmlHttp;
}catch(e)
{
//Do nothing
}
}
}else
{
throw new Error("XMLHttp object could be created.");
}
}
xmlHttp = CreateXMLHttp();
xmlHttp.setRequestHeader("Content-Type","text/xml");
xmlHttp.setRequestHeader("Content-Type","gb2312");
var xmlHttp=null;
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
catch(oc)
{
xmlHttp=null
}
}
if ( !xmlHttp && typeof XMLHttpRequest != "undefined" )
{
xmlHttp = new XMLHttpRequest()
}
Tags -
xmlhttp ,
对象 ,
浏览器 ,
msxml ,
ie ,
firefox