首页 技术 正文
技术 2022年11月12日
0 收藏 796 点赞 3,069 浏览 800 个字

背景:

本系统与门户系统单点登录时候,需要重定向到门户系统的登录页面,可是如果长时间没有操作的话,session会话失效,就需要跳转到登录页面。

所以在使用 response.sendRedirect(“…”)重定向URL后,在前段页面就会报

跨域问题Access to XMLHttpRequest’*’from origin ‘*’ has been blocked by CORS..Access-Control-Allow-Origin ……..等相关错误。

网上寻找了各种解决办法,可是在本系统中还是不适用,所以经过自己不断的尝试,终于找到解决办法,现在做一个分享!

解决办法:

       在前段页面,肯定会报这种类似的错误

Access to XMLHttpRequest at ‘*’ from origin ‘*’ 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.
这时,你不妨在JS报错的地方,把response的结果输入 console.log(“response=”,response),通过返回的response,来判断是哪种是属于重定向导致的报错,比如本系统中,我是这么操作的

       console.log("response==",response)
if (response.status == -) {
if(response.data == null){
window.location.reload();
} }

这种操作的结果,会直接刷新页面,也就是重定向的那个URL,跳转成功。

非常感谢您的阅读,如果这篇文章对您有所帮助,请随便打赏一下作为鼓励,我会再接再厉的!!!

使用js解决response.sendRedirect("…")重定向URL之后出现跨域问题

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918