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

二、原因

这是一个典型的跨域请求失败的例子。

三、解决

服务器的响应消息中增加头字段即可。

rsp.addHeader("Access-Control-Allow-Origin", "*");

四、扩展

更多的关于CORS的内容可以学习这篇文章:

https://yq.aliyun.com/articles/69313

原文地址:https://www.cnblogs.com/yoyotl/p/7098300.html