当我收到(xhr.response)的响应以充电页面时如何更改URL路径

时间:2018-12-30 21:53:43

标签: javascript node.js xmlhttprequest

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是受保护的路由”,如果没有令牌就无法获取它,

0 个答案:

没有答案