您的位置:首页 > 其它

(CORS)跨域资源共享方案

2014-10-15 18:02 253 查看
在XMLHttpRequest对象访问跨域资源的时候的一些被认可的跨域访问资源的方案叫

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

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

即可进行CORS。

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

function aCORSRequest(method,url){

var xhr = new XMLHttpRequest();

if('withCredentials' in xhr){
//准备请求
xhr.open(method,url,true);
}else if(typeof XDomainRequest != 'undefined'){

xhr = new XDomainRequest();

xhr.open(method,url);

}else{
xhr = null;
}

return xhr;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: