This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

The XMLHttpRequest Object

// button click event to load document
 onclick="loadDoc()"

// define loadDoc() function
function loadDoc() {
  const xhttp = new XMLHttpRequest();

// detects change in onreadystatechange
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML =
      this.responseText;
    }
  };

// defines the XMLHttpRequest Object
  xhttp.open("GET", "ajax_info.txt");
  xhttp.send();
}

The onreadystatechange event is triggered four times (1-4), one time for each change in the readyState.