- 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';
- }
- }
- });
来源: http://www.bubuko.com/infodetail-2875579.html