XHR对象

 1 function createXHR(){
 2      if(typeof XMLHttpRequest != "undefined"){
 3         createXHR = function(){
 4             return new XMLHttpRequest();
 5         };
 6      }else if(typeof ActiveXObject != "undefined"){
 7          createXHR = function(){
 8             if(typeof arguments.callee.activeXString != "string"){
 9              var versions = ["MSXML2.XMLHttp.6.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp"];
10              for(var i=0,len=versions.length;i<len;i++){
11                  try{
12                      var xhr = new ActiveXObject(versions[i]);
13                      arguments.callee.activeXString = versions[i];
14                      return xhr;
15                  }catch (ex){
16                      console.log("异常");
17                  }
18              }
19          }
20          return new ActiveXObject(arguments.callee.activeXString);
21          };
22      }else{
23          createXHR = function(){
24             throw new Error("No XHR object available.");
25          };
26      }
27      return createXHR();
28  }
posted @ 2012-06-05 20:29  小猩猩君  阅读(502)  评论(0编辑  收藏  举报