天天看点

获取xmlhttprequest对象

/**

 * 获取XmlHttpRequest对象

 */

function getXMLHttpRequest(){

   var xmlHttpReq;

   try{ // Firefox, Opera 8.0+, Safari

        xmlHttpReq=new XMLHttpRequest();

    }

    catch (e){

   try{// Internet Explorer

         xmlHttpReq=new ActiveXObject("Msxml2.XMLHTTP");

      }

    catch (e){

      try{

         xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP");

      catch (e){}

return xmlHttpReq;

 }

 var xmlHttpReq=null; 

 if (window.ActiveXObject) {//IE浏览器创建XMLHttpRequest对象

  xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");

 }else if(window.XMLHttpRequest){

   xmlHttpReq = new XMLHttpRequest();

     return xmlHttpReq;

}

function getXMLHttpRequest() {

var xmlHttpReq=null;

if (window.XMLHttpRequest) {//Mozilla 浏览器

xmlHttpReq = new XMLHttpRequest();

}else {

if (window.ActiveXObject) {//IE 浏览器

try {

xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

catch (e) {

try {//IE 浏览器

xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");

本文转自 素颜猪 51CTO博客,原文链接:http://blog.51cto.com/suyanzhu/1896875