jquery带token访问接口ajax
1.在公共js里全局设置
//设置全局ajax
$.ajaxSetup({
xhrFields: {
withCredentials: true
}
});
2.登录成功时,设置cookie (注: urlcore为全局url前缀)
//设置cookie
var domain_url = urlcore.split('://')[1];
if (domain_url.indexOf(':') > -1) {
domain_url = domain_url.split(':')[0];
}else{
domain_url = domain_url.split('/')[0];
}
document.cookie = "JSESSIONID="+data.data.token+";path=/;domain="+domain_url;