var xmlhttp;//全局使用 //除了IE6及其哥哥们外 其他浏览器创建XMLHttpRequest对象的代码 if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); //避免Mozilla早些版本会有的bug if(xmlhttp.overrideMimeType){ xmlhttp.overrideMimeType("text/xml"); } } //IE6 IE5 IE5.5创建XMLHttpRequest对象的代码 else if(window.ActiveXObject){ var activexName = ["MSXML2.XMLHTTP","Microsoft.XMLHTTP"]; //尝试创建 for(var i = 0;i<activexName.length;i++){ try{ xmlhttp = new ActiveXObject(activexName[i]); break; }catch(ex){} } } //查看结果 if(!xmlhttp){ alert("nothing is finded"); }else{ alert(xmlhttp);//IE6显示object 其他浏览器显示Object XmlHttpObject }