title: How to redirect from an xhr request
body: <p>When I send an xhr post request to my server. It replies with a 302 redirect, but I can only log the entire redirect html, and cannot get the browser to redirect to the new url.</p>
  
  <p>server.js</p>
  
  <pre><code>const Hapi = require('hapi');
  const Inert = require('inert');
  
  const server = new Hapi.Server();
  const port = 8888;
  
  server.connection({ port });
  
  server.register([ Inert ], () =&gt; {
    server.route([
      {
        method: 'get',
        path: '/',
        handler: (request, reply) =&gt; {
          reply.file('index.html');
        }
      },
      {
        method: 'get',
        path: '/login',
        handler: (request, reply) =&gt; {
          reply.file('login.html');
        }
      },
      {
        method: 'post',
        path: '/login',
        handler: (request, reply) =&gt; {
          reply.redirect('/');
        }
      }
    ]);
  
    server.start(() =&gt; {
      console.log('Server running on ', server.info.uri);
    });
  });
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;body&gt;
      &lt;h1&gt; Home &lt;/h1&gt;
      &lt;a href="/login"&gt; go to login &lt;/a&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>login.html</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;body&gt;
      &lt;button id="home"&gt;home&lt;/button&gt;
      &lt;script&gt;
        function goHome () {
          var xhr = new XMLHttpRequest();
          xhr.onreadystatechange = function () {
            if(xhr.readyState === 4 &amp;&amp; xhr.status === 200) {
              console.log('Response: ', xhr.response);
            }
          }
          xhr.open('post', '/login');
          xhr.send();
        }
        document.getElementById('home').addEventListener('click', goHome);
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Is there a way to redirect to '/' without doing it client side?</p>
  
  <p>Thanks in advance for the help</p>