Friday, January 26, 2018

write a program for AJAX response in javascript.

  • The readyState property holds the status of the XMLHttpRequest.
  • The onreadystatechange property defines a function to be executed when the readyState changes.
Program

<html>
<body>

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


<script>
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", "ajres.html", true);
  xhttp.send();
}
</script>

</body>
</html>

Output



0 comments:

Post a Comment

Thanks For Commented.

TechTalk