newxhr.open("GET","/connected", true);
newxhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
newxhr.setRequestHeader('Authorization', 'Bearer ' + JSON.parse(localStorage.getItem('token')));
newxhr.onreadystatechange = function() {
if(newxhr.readyState == XMLHttpRequest.DONE && newxhr.status == 200){
//The problem is here
window.location.href="/home";
}
}
实际位置是' / connexion ',该帖子起作用了,我从服务器获取了令牌,所以我将GET传递到了<< em> / home ',但它仍然位于同一页上:注意“ / home是受保护的路由”,如果没有令牌就无法获取它,