码迷,mamicode.com
首页 > Web开发 > 详细

获取xmlhttprequest对象

时间:2017-02-11 14:51:54      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:获取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;

 }

 

/**

 * 获取XmlHttpRequest对象

 */

function getXMLHttpRequest(){

var xmlHttpReq=null; 

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

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

}else if(window.XMLHttpRequest){

xmlHttpReq = new XMLHttpRequest();

}

     return xmlHttpReq;

}



/**

 * 获取XmlHttpRequest对象

 */

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");

}

catch (e) {

}

}

}

}

return xmlHttpReq;

}


 


本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1896875

获取xmlhttprequest对象

标签:获取xmlhttprequest对象

原文地址:http://suyanzhu.blog.51cto.com/8050189/1896875

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!