码迷,mamicode.com
首页 > 其他好文 > 详细

(CORS)跨域资源共享方案

时间:2014-10-15 20:56:11      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   java   sp   div   

在XMLHttpRequest对象访问跨域资源的时候的一些被认可的跨域访问资源的方案叫

(CORS)跨域资源共享方案。

在ie8中,可以通过XDomainRequest进行CORS,而在其他的浏览器中可以通过XHR对象

即可进行CORS。

代码取自javascript高级程序设计3版:

 1 function aCORSRequest(method,url){
 2     
 3     var xhr = new XMLHttpRequest();
 4     
 5     if(‘withCredentials‘ in xhr){
 6         //准备请求
 7         xhr.open(method,url,true);    
 8     }else if(typeof XDomainRequest != ‘undefined‘){
 9         
10         xhr = new XDomainRequest();
11         
12         xhr.open(method,url);
13         
14     }else{
15         xhr = null;    
16     }
17     
18     return xhr;
19     
20     
21 }

 

(CORS)跨域资源共享方案

标签:style   blog   http   color   io   ar   java   sp   div   

原文地址:http://www.cnblogs.com/hellome/p/4026969.html

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