前后端分离,客户端无法获得cookie--解决方法

news/2024/5/18 16:10:15 标签: cookie, ajax

前后端分离,客户端无法获得cookie--解决方法

问题:可能很多人在前后端分离开发时,发现抓包工具可以抓到cookie,但是在客户端上cookie的保存位置找不到该cookie

答:这是ajax本身的问题造成的,解决的办法就是在前端的ajax代码中,添加下面的代码即可:

 xhrFields:{withCredentials: true},

具体的添加位置如下面的代码:

ajax:function(url,parameter,fn){
			$.ajax({
		        url:this.CTX+url,
		        dataType:"json",
		        data:parameter,
			//该操作可以让客户端保存cookie,否则因为ajax本身的原因,cookie无法保存客户端(但是可以通过抓包工具获得)
		        xhrFields:{withCredentials: true},
		        success:function (data,status,xhr) {
		            //处理登录的filter
		            if(true){
		                fn(data,status,xhr);
		            }
		        }
		    })
		},

 


http://www.niftyadmin.cn/n/1435308.html

相关文章

VirtualBox:Ubuntu19.10 无法进入图形界面的解决方法

参考链接: https://blog.csdn.net/ithiker/article/details/85868320 内容都是抄人家的。大家可以直接看上面的参考链接。 解决方法: sudo apt-get install --reinstall libxkbcommon0startx /usr/bin/gnome-session

IDEA中Update resources和Update classes and resources、Redeploy、Restart server的区别

IDEA 中 Update resources 和 Update classes and resources、Redeploy、Restart server 的区别 update resources ---- 更新静态的资源,比如html,js,css等 运行模式和调试模式都是立即生效;update classes and resources ---- 更新java,jsp和静态资…

spec文件:目录

常用的目录: [adams~]$ rpm --eval "%{_mandir}" /usr/share/man [adams~]$ rpm --eval "%{_bindir}" /usr/bin [adams~]$ rpm --eval "%{_sbindir}" /usr/sbin [adams~]$ rpm --eval "%{_datadir}" /usr/share [adams~]$…

Spring 官方文档(中文翻译)

资源地址:https://www.jianshu.com/p/b3da0c8a22fe

RPM包制作:spec文件介绍

参考链接: https://rpmbuildtut.wordpress.com/ https://rpm-packaging-guide.github.io/#packaging-software https://rpm-packaging-guide.github.io/ http://rpm.org/index.html spec文件参数介绍 spec文件可以理解为安装软件包时的配置文件,配合…

Spring中使用@RunWith整合的测试注解

Spring中使用RunWith整合的测试注解 大家比较熟悉下面的代码: RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations{"classpath:applicationContext.xml"}) RunWith就是一个运行器 RunWith(JUnit4.class)就是指用JUnit4来运行 Ru…

Linux:监控鼠标_C代码

程序&#xff1a; #include <sys/types.h> #include <fcntl.h> #include <time.h> #include <stdio.h> #include <unistd.h> #include <linux/input.h>void listen_mice(const char *dev, int timeout) {char buf[256];int n_len;int ret…

Linux:监控键盘_C代码

程序&#xff1a; #include <sys/types.h> #include <fcntl.h> #include <time.h> #include <stdio.h> #include <unistd.h> #include <linux/input.h>void listen_device(const char *dev, int timeout) {int retval;fd_set readfds;str…