Programming in Ajax - Named Callback Functions

// 2. Named Callback Functions

<!DOCTYPE html>

<html>

<head>

<script>

     function loadDoc(fncall)

     {

          var xhttp=new XMLHttpRequest();

 

          xhttp.onreadystatechange = function()

          {

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

              {

                   fncall(this);

              }

          };

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

          xhttp.send();

     }

    

     function CallBkFn(xhttp)

     {

          document.getElementById("demo").innerHTML =  xhttp.responseText;

     }

</script>

</head>

<body>

<div id="demo">

<h2>Ajax callback functions </h2>

<button type="button" onclick="loadDoc(CallBkFn)"> 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