5
我正在为应用程序设置身份验证。在发出登录请求后,将发送一个JSON Web令牌作为响应。我可以通过Ajax将其附加到标题。问题是当使用window.location.pathname在登录后重定向时,因为它不是Ajax请求,它没有将标记附加到标题。我如何解决这个问题?将标题添加到window.location.pathname
$.ajaxSetup({
headers: {
'x-access-token': window.localStorage.jwt
}
});
var Auth = {
signup: function() {
console.log('signuppp');
var userSignup = {
username: $('#usernameSignup').val(),
password: $('#passwordSignup').val()
};
console.log(userSignup)
return $.post('/api/users/register', userSignup, function (resp) {
console.log('resp: ',resp);
window.localStorage.setItem('jwt', resp.token);
//does not have x-access-token header
window.location.pathname = '/';
})
},