前后端分离,解决session 刷新变ID

通过API接口实现前后端分离的项目,请求session ID 刷新就会改变,造成不断生成新的SESSION文件

 

1、$.ajax解决方案:

设置:

xhrFields: {
withCredentials: true
}

$.ajax({
 url:api+'user/islogin',
 xhrFields: {
       withCredentials: true
 },
 data:postdata,
 type:'json',
 method:'post',
 success:function(e){

 }

})

 

2、axios解决方案

axios.defaults.withCredentials = true;

 

posted @ 2021-01-29 02:34  yonomo  阅读(708)  评论(0)    收藏  举报