1. 直接步入主题,遇到的问题如下
Access to XMLHttpRequest at ‘http://localhost:8080/ycbike_back/findbike.action’ from origin ‘http://localhost’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
POST http://localhost:8080/ycbike_back/findbike.action net::ERR_FAILED
翻译:访问位于’http://localhost:8080/ycbike_背面/findbike.action’来源’http://localhost’已被CORS策略阻止:请求的资源上不存在“Access Control Allow Origin”标头。
2. 根据错误提示,判断为跨域请求的问题,即:服务端和请求端的地址不一样。
跨域的详细介绍原理可以参考:浏览器和服务器实现跨域(CORS)判定的原理
3.根据网上资料,总结为两种方案解决问题(个人使用的是第一种方案)
(1)如果是使用Spring Boot创建的项目,直接添加@CrossOrigin
注解到方法上就可以了。
(2)如果是servlet方法,则可在请求方法上加入下列代码
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Cache-Control","no-cache");
本文地址:https://blog.csdn.net/weixin_44422604/article/details/107283456
如对本文有疑问, 点击进行留言回复!!
Parallels Desktop v15.1.4-47270 商业版下载 Mac安装Windows首选虚拟机
关于LPC824Lite开发板下载程序时提示"Invalid ROM Table"
MySQL 5.7 关于 JSON 类型的子集Key/Value获取方法分享
javascript从入门到跑路-----小文的js学习笔记(19)------- js的垃圾回收机制
网友评论