在开发中,前端同事调用后端同事写好的接口,在地址中是有效的,但在项目的ajax中,浏览器会报 "No 'Access-Control-Allow-Origin' header is present on the requested resource"的错误。

这是由于浏览器禁止ajax请求本地以外的资源,解决办法如下:

后端同事在Controller层的类上增加@CrossOrign注解,当前文件的所有接口就都可以被调用。

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @CrossOrigin
@RestController
@RequestMapping("test")
public class TestController { @RequestMapping("/one")
public Object one(HttpServletRequest request){
System.out.println("请求成功");
return "请求成功";
} .... }

SSM处理 No 'Access-Control-Allow-Origin' header is present on the requested resource 问题的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 跨域问题解决----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 ...

  5. 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 ...

  6. .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 ...

  7. 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 ...

  8. (转)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 ...

  9. 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 'Ac ...

随机推荐

  1. ssh 远程登录错误

    错误信息: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: REMOTE HOST IDENTIFICATI ...

  2. jxbrowser 实现自定义右键菜单

    https://blog.csdn.net/shuaizai88/article/details/73743691 public static void main(String[] args) { J ...

  3. 网络通信框架之retrofit

    主页: [https://github.com/square/retrofit](https://github.com/square/retrofit) 注意: 使用Retrofit的前提是**服务器 ...

  4. js如何获取window.location.href跳转后查询字符串的值?

    $("#worked_count").parent().attr("onClick","window.location.href='view/warn ...

  5. Eclipse-jee-oxygen-3A版运行时出现Could not create the Java virtual machine?

    我有她就够了!!! 详情点击:[她]

  6. idea关闭自动更新

    如何关闭idea的自动更新? File-Setting-Appearance&Beha-System Setting-Updates 取消勾选Automatically check updat ...

  7. Linux后台运行python程序并输出到日志文件

    后台运行python程序并标准输出到文件 现在有test.py程序要后台部署, 里面有输出内容 使用命令: nohup python -u test.py > test.log 2>&am ...

  8. 状态压缩DP:蒙德里安的梦想

    代码 #include<bits/stdc++.h> using namespace std; int n,m; long long f[12][1<<11]; bool yy ...

  9. 应用安全 - 工具|平台 - Elasticsearch- 漏洞 - 汇总

    未授权访问 (1)/_cat/indices #Index个数查询 (2)/_mapping?pretty=true #type个数查询 (3)根据Index和type查询表数据 (4)/_river ...

  10. HDU 1260 Tickets (动态规划)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...