Response to preflight request doesn‘t pass access control check: No ‘Access-Control-Allow-Origin‘

Access to XMLHttpRequest at ‘http://zqq.com:8080/portal/login/loginAction!testOtherSysRequest.action’ (redirected from ‘http://127.0.0.1:8080/portal/login/loginAction!redirectOtherSys.action’) from origin ‘http://127.0.0.1:8080’ 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.

1、报错片段

下面展示一些 内联代码片

Access to XMLHttpRequest at 'http://zqq.com:8080/portal/login/loginAction!testOtherSysRequest.action' (redirected from 'http://127.0.0.1:8080/portal/login/loginAction!redirectOtherSys.action') from origin 'http://127.0.0.1:8080' 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.
2、分析原因及解决

网上有好多的解决方案都是加这个
response.setHeader(“Access-Control-Allow-Origin”, “*”);
response.setHeader(“Access-Control-Allow-Methods”, “POST, GET, PUT, OPTIONS, DELETE”);
但我加上这个也没用,找找找,终于在大佬的帮助下找到了问题所在:在调用重定向接口过程中用了ajax请求进行访问,导致浏览器总是报上面的错误,改为window.location.href=XXX问题终于解决了

你可能感兴趣的:(前端,java)