title: How to make an XMLHttpRequest that loads an HTML file into the div?
body: <p>I'm trying to make an <code>XMLHttpRequest</code> that loads HTML from an external file and inserts the content of the file into the <code>div</code>.</p>
  
  <p>When I run the function, it inserts the HTML in all of the body which is not adequate.</p>
  
  <p>My code:</p>
  
  <p>--------------------------> <strong>HTML</strong> &lt;--------------------------
  </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;script src="shit.js" charset="utf-8"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" href="index.css"&gt;
      &lt;title&gt;Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;button type="button" name="button" onclick="send()"&gt;Click me&lt;/button&gt;
      &lt;div class="view" id="view"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>--------------------------> <strong>CSS</strong> &lt;--------------------------</p>
  
  <pre class="lang-css prettyprint-override"><code>.view {
      margin-top: 5vh;
      height: 15vh;
      width: 80vw;
      background-color: #c1c1c1;
  }
  </code></pre>
  
  <p>--------------------------> <strong>JS</strong> &lt;--------------------------</p>
  
  <pre class="lang-js prettyprint-override"><code>function send() {
      var xmlhttp = new XMLHttpRequest();
  
      xmlhttp.onreadystatechange = function () {
          if (xmlhttp.readyState == 4) {
              document.write(xmlhttp.responseText);
          }
      }
  
      var params = "type=search" + "&amp;content=" + encodeURIComponent(document.getElementById("view").innerHTML);
  
      xmlhttp.open("GET", "/include/link1.html", true);
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlhttp.setRequestHeader("Content-length", params.length);
      xmlhttp.send(params);
  }    
  </code></pre>
  
  <p>Thanks in advance.</p>