我正在處理令牌,並且每個HTTP請求都會將令牌添加到頭部,以便服務器可以判斷用戶是否已登錄。
因此,我無法重定向到特定的URL並檢查令牌,因爲令牌不會被添加到標頭。
是否可以從http請求中加載新的HTML頁面?每次服務器響應時,我都會得到HTML頁面的代碼。我認爲角度不會重新加載新的傳入頁面。
編輯:下面是增加每個HTTP請求
// ===================================================
// application configuration to integrate token into requests
// ===================================================
.factory('AuthInterceptor', function($q, $location, AuthToken) {
var interceptorFactory = {};
// this will happen on all HTTP requests
interceptorFactory.request = function(config) {
// grab the token
var token = AuthToken.getToken();
// if the token exists, add it to the header as x-access-token
if (token) {
config.headers['x-access-token'] = token;
}
return config;
};
// happens on response errors
interceptorFactory.responseError = function(response) {
// if our server returns a 403 forbidden response
if (response.status == 403) {
AuthToken.setToken();
$location.path('/login');
}
// return the errors from the server as a promise
return $q.reject(response);
};
return interceptorFactory;
});
我使用的UI路由一些代碼
代碼。我有一個網站的前端和後端。因此,當用戶從前端登錄時,front-end.html消失,back-end.html被加載。但角度只是讀取後端HTML代碼。
您的代碼在哪裏?你的意思是不會將標記添加到標題中?你是否存儲令牌客戶端添加它添加到'$ http.defaults.headers.common'? – matthewpavkov
已更新,相關代碼 –
@StevenR您是否嘗試實施跨站點腳本修復? – pratikpawar