title: what callback function should i use in an XMLHttpRequest to render the response?
body: <p>After a user does something on a page, I use ajax to send some data to my Node.js Express server. That server then does this:</p>
  
  <pre><code>router.post('/', function(req, res){
  //user authentication then, inside that callback
    res.redirect('/dashboard');
  }
  </code></pre>
  
  <p>dashboard.js then does this:</p>
  
  <pre><code>router.get('/', function(req, res, next) {
      console.log("dashboard"); //&lt;--This code is running
      res.render('index',{title:"You are logged in"});
  }
  </code></pre>
  
  <p>Now the front end is doing this:</p>
  
  <pre><code>function httpGetAsync(theUrl, callback){
          let user = document.getElementById('username').value;
          let pass = document.getElementById('password').value;
          let data = {
              "username": user,
              "password": pass
          }
          var xmlHttp = new XMLHttpRequest();
          xmlHttp.onreadystatechange = function() {
              if (xmlHttp.readyState == 4 &amp;&amp; xmlHttp.status == 200)
                  callback(xmlHttp.responseText);
          }
          xmlHttp.open("POST", theUrl, true); // true for asynchronous
          xmlHttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
          var dataAsJson = JSON.stringify(data);
          xmlHttp.send(dataAsJson);
      }
  </code></pre>
  
  <p>Instead of seeing my nice "You are logged in" page, index.html logs to my browser's console. This is obviously because my onclick listener does this:</p>
  
  <pre><code>onclick='httpGetAsync("/createUser", console.log)'
  </code></pre>
  
  <p>Instead of <code>console.log</code> (which is obviously the wrong thing here), what should I be calling?</p>
  
  <p>How do I get this <code>res.render('index',{title:"You are logged in"})</code> in dashboard.js to actually render?</p>
  
  <p>This is a lot like <a href="https://stackoverflow.com/questions/27202075/expressjs-res-redirect-not-working-as-expected">ExpressJS : res.redirect() not working as expected?</a>, but that question does not include the portion that includes their front end code which is where I think the problem lies. And the last comment there reads: "No, never figured it out. I ended up building my app differently, with the login part in a modal, instead of another page... Very frustrating".</p>