跨浏览器的CORS

 1 function createCORSRequest(method, url){
 2      var xhr = new XMLHttpRequest();
 3      
 4      if("withCredentials" in xhr){
 5          xhr.open(method, url, true);
 6      }else if(typeof XDomainRequest != "undefined"){
 7          xhr = new XDomainRequest();
 8          xhr.open(method, url);
 9      }else{
10          xhr = null;
11      }
12 
13      return xhr;
14 }
15 
16 var request = createCORSRequest("get", "http://www.somewhere-else.com/page/");
17 
18 if(request){
19     request.onload = function(){
20          //对request.responseText 进行处理
21     }
22 
23     request.send();
24 }
原文地址:https://www.cnblogs.com/yiliweichinasoft/p/3807362.html