首页 > 数据库技术 > 详细

No 'Access-Control-Allow-Origin' header is present on the requested resource.

时间:2016-04-08 00:44:41      阅读:341      评论:0      收藏:0      [点我收藏+]

今天做一个AJAX案例时,浏览器监控到如下错误:

XMLHttpRequest cannot load http://54.169.69.60:8081/process_message. No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. Origin ‘http://54.169.69.60‘ is therefore not allowed access.

网站地址是 http://54.169.69.60/qnow/ 而 AJAX URL 是 http://54.169.69.60:8081/process_message,两个端口不一致,因此要跨域。

 

Access-Control-Allow-Origin是HTML5中定义的一种服务器端返回Response header,用来解决资源(比如字体)的跨域权限问题。

它定义了该资源允许被哪个域引用,或者被所有域引用(google字体使用*表示字体资源允许被所有域引用)。

 

解决方法:

根据错误信息可知,必须给 header 加上头部 Access-Control-Allow-Origin,比如我的是 Node.js,这样写:

response.type(‘application/json‘);
response.status(200);
response.append(‘Access-Control-Allow-Origin‘, "*");
if (err) {
    response.json({ result: ‘error‘, message: err });
}
else {
    response.json({ result: ‘success‘, message: res.message });
}

 

No 'Access-Control-Allow-Origin' header is present on the requested resource.

原文:http://www.cnblogs.com/felixnet/p/5364617.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!