原创转载请注明出处:http://agilestyle.iteye.com/blog/2353274
通常项目开发中我们通常会遇到跨域调用,然后当请求调用的时候会遇到这个错
No 'Access-Control-Allow-Origin' header is present on the requested resource.
通常解决这个错误有两种解决方法
1. JSONP
2. CORS
Note:
CORS与JSONP相比,更为先进、方便和可靠。
- JSONP只能实现GET请求,而CORS支持所有类型的HTTP请求。
- 使用CORS,开发者可以使用普通的XMLHttpRequest发起请求和获得数据,比起JSONP有更好的错误处理。
- JSONP主要被老的浏览器支持,它们往往不支持CORS,而绝大多数现代浏览器都已经支持了CORS。
但是呢,现在你的项目还是在开发阶段,比如技术选型POC阶段,用不着搞得这么复杂,所以最简单的方法就是在Chrome中安装一个插件Allow-Control-Allow-Origin,可以快而有效的解决这类问题。
安装后
开启CORS,再次调试跨域调用,错误就没有了
相关推荐
静态文件访问不到报No 'Access-Control-Allow-Origin' header is present on the requested resource处理办法
add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET,POST'; 使用以下配置,生效。 if ($request_method = '...
解决浏览器跨域请求出现No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.问题
【Redirect at origin ‘http://sub1.xx.com’ has been blocked from loading by Cross-Origin Resource Sharing policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource....
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch ...
本文通过设置Access-Control-Allow-Origin来实现跨域。 ... 如果直接使用ajax访问,... No ‘Access-Control-Allow-Origin’ header is present on the requested resource.Origin ‘http://client.runoob.com’ is theref
vue项目中,前端与后台进行数据请求或者提交的时候,如果后台没有设置跨域,前端本地调试代码的时候就会报“No ‘Access-Control-Allow-Origin’ header is present on the requested resource.” 这种跨域错误。...
/// 2、“has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.”。 /// 3、“has been blocked by CORS policy: Response to preflight request...
构建该模块是为了解决出现此错误的问题: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque ...
No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://当前页的域名’ is therefore not allowed access. 2、为什么会出现跨域问题 因为浏览器收到同