title: How to check if user who open webpage has JWT token? Using JS and AJAX
body: <p>I have a webpage, hosted locally. When I type in localhost:1111, my page should check if I have a JWT token in the "Request" (I believe) and if I do, display it, if not redirect me to a login page that will handle getting the JWT. </p>
  
  <p>Right now it always redirects me to the login page. Even after I login, it opens my page and then automatically redirects to the login page again. I believe I need to use AJAX to listen for requests for my page and handle the request there.</p>
  
  <p>This is the code i have so far</p>
  
  <pre><code>$(window).ready(function() {
      if (this.response == null)
      {
          window.location.href = "LOGIN-PAGE.COM";
      }
      else
      {
          var responseObject = JSON.parse(this.response);
  
          if (responseObject.token) 
          {
              document.getElementById("userDetails").innerHTML = responseObject.token;
          } 
          else 
          {
              document.getElementById("userDetails").innerHTML = "No token received";
          }
      }
  
  } )
  </code></pre>
  
  <p>And it obviously doesn't work. Im new to web stuff but I have some experience with JS.</p>