Ajax请求Access-Control-Allow-Origin错误解决
发布时间:2020-12-16 03:10:29 所属栏目:百科 来源:网络整理
导读:在JS中使用AJAX请求跨域时候,会提示错误 Failed to load http://localhost:8889/xxxxxxxxx: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8085' is therefore not allowed access. 这个是提示
在JS中使用AJAX请求跨域时候,会提示错误 Failed to load http://localhost:8889/xxxxxxxxx: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8085' is therefore not allowed access. 这个是提示服务端没有设置'Access-Control-Allow-Origin', 以Spring mvc为例 设置Access-Control-Allow-Origin即可,如下: @RequestMapping(value = "/test",method = RequestMethod.POST) @ResponseBody public String test(String param,HttpServletResponse response) { response.setHeader("Access-Control-Allow-Origin","*"); return "test"; } 设置Header值,完成后重启服务, 即可正常访问! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- swift – 对成员的模糊引用\u0026\u0026 [复制]
- 在没有默认值的情况下将非DateTime列添加到SQLite?
- C#中序列化实现深拷贝,实现DataGridView初始化刷新的方法
- NAND FLASH学习笔记之MTD下nand flash驱动(七)---我的调试
- 数据存储-XML文件(DOM/SAX/PULL解析)
- 82.You are managing an Oracle Database 11g database wit
- ios – Xcode 6 Beta7 NSDictionary到Swift
- cocos2dx-3.X中对事件处理分析(1)
- ruby-on-rails – Rails – 这样安全吗?使用URL参数查询数
- 破解优酷土豆播放器过程