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

获取XMLHttpRequest对象

时间:2015-09-05 11:09:33      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

 1 //创建一个XMLHttpRequest对象 ,利用此对象与服务器进行通信 是AJAX技术的核心
 2 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
 3 function ajaxFunction(){
 4    var xmlHttp;
 5    try{ // Firefox, Opera 8.0+, Safari
 6         xmlHttp=new XMLHttpRequest();
 7     }
 8     catch (e){
 9        try{// Internet Explorer
10              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
11           }
12         catch (e){
13           try{
14              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
15           }
16           catch (e){}
17           }
18     }
19 
20     return xmlHttp;
21  }
22 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
23 function getXMLHttpRequest(){
24      var xmlHttpReq=null; 
25      if (window.ActiveXObject) {//IE浏览器创建XMLHttpRequest对象
26          xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
27      }else if(window.XMLHttpRequest){
28           xmlHttpReq = new XMLHttpRequest();
29      }
30      return xmlHttpReq;
31 }
32 
33 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
34 
35 /**
36  * 获取XmlHttpRequest对象
37  */
38 function getXMLHttpRequest() {
39     var xmlHttpReq=null;
40     if (window.XMLHttpRequest) {//Mozilla 浏览器
41         xmlHttpReq = new XMLHttpRequest();
42     }else {
43         if (window.ActiveXObject) {//IE 浏览器
44             try {
45                 xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
46             }
47             catch (e) {
48                 try {//IE 浏览器
49                     xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
50                 }
51                 catch (e) {
52                 }
53             }
54         }
55     }
56     return xmlHttpReq;
57 }
58 
59  

 

获取XMLHttpRequest对象

标签:

原文地址:http://www.cnblogs.com/0519xf/p/4782815.html

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