Load something after Page load with XMLHttpRequest - Javascript Language Basics

Javascript examples for Language Basics:XMLHttpRequest

Description

Load something after Page load with XMLHttpRequest

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div id="demo"> 
         <h2>The XMLHttpRequest Object</h2> 
         <button type="button" onclick="loadDoc()">Change Content</button> 
      </div> 
      <script>
function loadDoc() {//from  w  ww. ja  va 2 s .  c o m
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML =
      this.responseText;
    }
  };
  xhttp.open("GET", "/your.php", true);
  xhttp.send();
}

      </script>  
   </body>
</html>

Related Tutorials