title: How to get the html from a url?
body: <p>This is not a duplicate of "How does Access-Control-Allow-Origin header work?".</p>
  
  <p>I read some Q&amp;A like "How to send GET request in JavaScript?" but the answers do not work (for example, <a href="https://stackoverflow.com/a/4033310/13054677">this</a>).</p>
  
  <p>The error is as follows:</p>
  
  <blockquote>
    <p>Access to XMLHttpRequest at '<a href="https://~" rel="nofollow noreferrer">https://~</a>' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.</p>
  </blockquote>
  
  <p>Could you give me an example of working code?</p>
  
  <p>I want to get the html of the target URL.</p>
  
  <p>my code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;script&gt;
              var theUrl = "https://www.google.com";
  
              function httpGetAsync(theUrl, callback)
              {
                  var xmlHttp = new XMLHttpRequest();
                  xmlHttp.onreadystatechange = function() { 
                      if (xmlHttp.readyState == 4 &amp;&amp; xmlHttp.status == 200)
                          callback(xmlHttp.responseText);
                  }
                  xmlHttp.open("GET", theUrl, true); // true for asynchronous 
                  xmlHttp.send(null);
              }
  
              function callback(text){
                  console.log(text);
              }
  
              httpGetAsync(theUrl, callback);
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>