Programming in Ajax - Anonymous Callback Functions

// 1. Anonymous Callback Functions

<!DOCTYPE html>

<html>

<head>

<script>

function loadDoc()

{

     var xhttp = new XMLHttpRequest();

 

     // Callback using Anonymous Function

     xhttp.onreadystatechange = function()

     {

          if (this.readyState == 4 && this.status == 200)

          {

              document.getElementById("id1").innerHTML = this.responseText;

          }

     };

     xhttp.open("GET", "Hello.txt", true);

     xhttp.send();

}

</script>

</head>

<body>

<div id="id1">

<h2>The XMLHttpRequest Object</h2>

<h2>Ajax – Anonymous Callback Functions <h2>

<button type="button" onclick="loadDoc()">Change Content</button>

</div>

</body>

</html>

 

 

// Input file - Hello.txt

<h2>Hello and Welcome to Ajax</h2>

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu