title: JavaScript: alert XHR response?
body: <p>I'm trying to <code>alert();</code> the response for a webpage. But the alert popup is blank. The HTTP request returns status 200 and I can see the response HTML in the browser console Network tab.</p>
  <p>I've tried examples shown <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText" rel="nofollow noreferrer">here</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response" rel="nofollow noreferrer">here</a>, and <a href="https://stackoverflow.com/questions/3038901/how-to-get-the-response-of-xmlhttprequest">here</a>. The alert window is always blank...</p>
  <p>What am I getting wrong here? (I'm new to JS).</p>
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
     &lt;body&gt;
        &lt;script type=&quot;text/javascript&quot;&gt;
          var xhr = new XMLHttpRequest();
          xhr.open(&quot;GET&quot;, &quot;https://website.com/page&quot;, true);
          xhr.withCredentials = true;
          xhr.send();
          
          alert(xhr.response);
          alert(xhr.responseText);
        &lt;/script&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>