js ajax

by Alejandro M

HTML

<div id="demo">
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>

https://www.w3schools.com/xml/dom_http.asp

JavaScript

function loadDoc() {
  var xhttp = new XMLHttpRequest();
    xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML =
      this.statusText;
    }
  };
}