Javascript 加载带有$http请求的新HTML页面
我处理的是令牌,对于每个HTTP请求,令牌都会添加到头中,这样服务器就可以判断用户是否登录 因此,我无法重定向到特定的URL并检查令牌,因为令牌不会添加到头中 是否可以从http请求加载新的HTML页面?每次服务器响应时,我都会得到HTML页面的代码。我认为angular不会重新加载新的传入页面 编辑:这里有一些代码 添加到每个http请求的代码Javascript 加载带有$http请求的新HTML页面,javascript,html,angularjs,Javascript,Html,Angularjs,我处理的是令牌,对于每个HTTP请求,令牌都会添加到头中,这样服务器就可以判断用户是否登录 因此,我无法重定向到特定的URL并检查令牌,因为令牌不会添加到头中 是否可以从http请求加载新的HTML页面?每次服务器响应时,我都会得到HTML页面的代码。我认为angular不会重新加载新的传入页面 编辑:这里有一些代码 添加到每个http请求的代码 // =================================================== // application confi
// ===================================================
// 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将被加载。但是angular只读取back-end.html代码
// function to handle login form
vm.doLogin = function() {
vm.processing = true;
//clear the error
vm.error = '';
Auth.login(vm.loginData.email, vm.loginData.password)
.success(function (data) {
vm.processing = false;
// if a user successfully logs in, redirect to main application
if (data.success)
return $http.get('/account');
//Here is where a user logs in and i redirect them to the backend of the site. But the response is the HTML code of the page. I want that page to load.
else
vm.error = data.message;
});
};
你走错方向了。 您应该阅读以下内容:
您的代码在哪里?您认为令牌不会添加到标头是什么意思?是否存储令牌客户端添加将其添加到
$http.defaults.headers.common
?已更新相关code@StevenR您是否正在尝试实施跨站点脚本的修复程序?@pratikwebdev否,实际上我正在尝试将我的网站分为两个不同的部分。前端和后端,但后端具有令牌检查,以查看用户是否已登录以继续。因此,我无法直接转到后端URL,因为这样它们将没有令牌。@StevenR您可以尝试在会话变量中保存token
,而不是request header
,并在后端验证相同。我的2美分。这并不能回答问题,更适合作为对问题的评论——它可能会吸引反对票。