ajaxSetup全局配置,发送前和接收响应后
作者:互联网
$.ajaxSetup({
//在请求发送之前执行,将token发送过去
beforeSend(xhr,setting){
let token = localStorage.getItem("token");
xhr.setRequestHeader("x-access-token",token);
},
//在请求完成响应返回时执行
complete(xhr, setting) {
if (xhr.responseJSON.code === 401) {
alert(xhr.responseJSON.message);
router.go('/index');
}
}
})
标签:responseJSON,发送,xhr,token,setting,全局,ajaxSetup 来源: https://www.cnblogs.com/ltfxy/p/12585806.html