ajax全局配置token和token失效后的跳转

$.ajaxSetup(
    {
        headers: {
            access_token: localStorage.getItem('access_token')
        },
    }
);
$(document).ajaxComplete(function (event, xhr, options) {
    if (xhr.responseJSON.msg === 'token失效') {
        layer.msg('登录超时,即将跳转至登录页。。。', {
            icon: 2,
            time: 2000
        }, function () {
            location.href = '../../pages/user/login.html';
        });
    }
});

 

你可能感兴趣的:(ajax,ajax)