Tag: XMLHttpRequest

兼容XMLHttpRequest实例化函数.

function getXmlHttp(){
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
xmlhttp = null;
}
}
if (xmlhttp==null && typeof XMLHttpRequest!="undefined"){
try
{
xmlhttp=new XMLHttpRequest();
xmlhttp.overrideMimeType('text/xml');
}catch(e){
xmlhttp=false;
}
}
return xmlhttp;
}

以上函数是我最近一次实例XMLHttpRequest的方法.

早先进行实例的时候,是先处理支持XMLHttpRequest类的标准浏览器,再处理IE这种使用ActiveX实现XMLHttpRequest.

但是前几天发现,似乎IE7已经开始支持XMLHttpRequest,但是使用工程中有发现有点问题,就有改了一下,使用上面这个函数来获取XMLHttpRequest支持.

Tags: , , ,

Friday, May 30th, 2008 w3c 3 Comments