Saturday, April 17, 2021

Examples in Every Chapter

Examples in Every Chapter In every chapter, you can edit the examples online, and click on a button to view the result.


<!DOCTYPE html>
<html>
<body>
<div id="demo">
  <h2>Let AJAX change this text</h2>
  <button type="button" onclick="loadDoc()">Change Content</button>
</div>
</body>
</html>

 

The HTML page contains a <div> section and a <button>. The <div> section is used to display information from a server. The <button> calls a function (if it is clicked). The function requests data from a web server and displays it:

 

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

1 comment: