利用ajax全局设置实现拦截器

时间:2018-12-07 10:58:16   收藏:0   阅读:1735
var token = localStorage.getItem("token");

$.ajaxSetup({
	dataType: "json",
	cache: false,
    headers: {
        "token": token
    },
    xhrFields: {
	    withCredentials: true
    },
    complete: function(xhr) {
        //token过期,则跳转到登录页面
        if(xhr.responseJSON.code == 401){
            parent.location.href = baseURL + ‘login.html‘;
        }
    }
});

  

原文:https://www.cnblogs.com/randomlee/p/10080896.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!