No 'Access-Control-Allow-Origin' header is present on the requested resource.
今天做一个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.的更多相关文章
- WCF REST开启Cors 解决 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 405.
现象: 编写了REST接口: [ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(UriTemp ...
- Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fromHere.com' is therefore not allowed access.
Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is presen ...
- java、ajax 跨域请求解决方案('Access-Control-Allow-Origin' header is present on the requested resource. Origin '请求源' is therefore not allowed access.)
1.情景展示 ajax调取java服务器请求报错 报错信息如下: 'Access-Control-Allow-Origin' header is present on the requested ...
- 跨域问题解决----NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost:11000' is therfore not allowed access'
NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost ...
- has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
前端显示: has been blocked by CORS policy: Response to preflight request doesn't pass access control che ...
- .Net Core 处理跨域问题Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
网页请求报错: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Or ...
- js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource
js跨域访问提示错误:XMLHttpRequest cannot load http://...... No 'Access-Control-Allow-Origin' header is prese ...
- (转)AJax跨域:No 'Access-Control-Allow-Origin' header is present on the requested resource
在本地用ajax跨域访问请求时报错: No 'Access-Control-Allow-Origin' header is present on the requested resource. Ori ...
- ajax请求node.js接口时出现 No 'Access-Control-Allow-Origin' header is present on the requested resource错误
ajax请求node.js接口出现了如下的错误: XMLHttpRequest cannot load http://xxx.xxx.xx.xx:8888/getTem?cityId=110105&a ...
随机推荐
- Junit单元测试笔记
什么是单元测试? 单元测试是开发者编写的一小段代码,用于检验被测代码的一个很小的.很明确的功能是否正确. 单元测试目的? 执行单元测试,是为了证明某段代码的行为确实和开发者所期望的一致. 白盒测试和单 ...
- ae
根据属性提取要素(利用GP) http://blog.csdn.net/ewyetc/article/details/6746728
- windows server2008 安装问题、sqlserver安装设置默认账户问题
1.Bios中的satadata设置开启 2账户和密码最好与本机相同
- 配置redis外网可访问,并只允许指定的ip可访问redis
开启redis 允许外网IP 访问 在 Linux 中安装了redis 服务,当在客户端通过远程连接的方式连接时,报could not connect错误. 错误的原因很简单,就是没有连接上redis ...
- 操作系统开发系列—13.a.进程 ●
进程的切换及调度等内容是和保护模式的相关技术紧密相连的,这些代码量可能并不多,但却至关重要. 我们需要一个数据结构记录一个进程的状态,在进程要被挂起的时候,进程信息就被写入这个数据结构,等到进程重新启 ...
- 修改 Android 5.x 系统默认音量大小
修改系统默认音量需要改两处地方: 1. frameworks\base\media\java\android\media\AudioManager.java /** @hide Default vol ...
- Loader加载器
今天学到了这个Loader,浅谈一下自己的看法: 1.定义 Loader是一个加载器,可以用来它访问数据,可以看做访问数据的机器(好比挖掘机).装再器从android3.0开始引进,它使得在activ ...
- 【代码笔记】iOS-带输入框的UIAlertView
一,效果图. 二,代码. //点击任何处,弹出输入框 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UIAlertV ...
- JSON TO NSDictionary Mac & iOS
NSString * jsonPath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Cont ...
- mysql命令(数据库备份与恢复)
本地: 1.进入MySQL目录下的bin文件夹:e:回车: e:\>cd mysql\bin? 回车 2.导出数据库:mysqldump -u 用户名 -p 数据库名 > 导出的文件名 范 ...