0
我的http請求在我的令牌在第一次刷新過期後無效,但在第二次刷新時可以正常工作,但該函數正在執行正確的錯誤。我在角框架工作http請求不在刷新頁面執行
$http({
url: "http://localhost/ArisSystem/api/system/subsystem",
method: "GET",
dataType: 'json',
ContentType: 'application/x-www-form-urlencoded',
params: {
parentId: $scope.systemIdToLoad
},
headers: authHeaders
}).then(function (response) {
$scope.subsystem = response.data;
}), function (xhr, status, error) {
if (refreshtoken && xhr.status === 401) {
$scope.refreshlocal();
}
}
$scope.refreshlocal = function() {
$.ajax({
url: "http://localhost/ArisSystem/login",
data: {
refresh_token: refreshtoken,
grant_type: 'refresh_token'
},
type: 'POST',
dataType: 'json',
ContentType: 'application/x-www-form-urlencoded',
success: AjaxSucceeded,
error: AjaxFailed
})
function AjaxSucceeded(response) {
localStorage.setItem('accessToken', response.access_token);
localStorage.setItem('refreshToken', response.refresh_token);
refreshtoken = localStorage.getItem('refreshToken');
accesstoken = localStorage.getItem('accessToken');
authHeaders.Authorization = 'Bearer ' + accesstoken;
}
function AjaxFailed(err, response) {
window.location.href = "login.html"
}
}
非常感謝,節省了我一天的時間 – hamed