Once we have send the request to the server , its time to receive the response and handle it. Here is the way to handle. I will explain it after the code

  http.onreadystatechange = useHttpResponse; 
  function useHttpResponse() {
   if (http.readyState == 4) {
    if(http.status == 200) {
      var mytext = http.responseText;
  document.getElementById('myDIvName').innerHTML = mytext;
  else {
  document. getElementById(id).innerHTML = "Requesting ....";


Starting with the first line of code, onreadystatechange stores a function (here useHttpResponse) to be called automatically each time the readyState property changes. This function is called everytime the readyState property changes.If readyState becomes 4 i.e. everything has been downloaded, and status is 200, then we get the response from the server. Now, once the response has been received, we can use it and place in any div or place on the website of our choice.Till the time the request is received, we either show a loader image or some text like "loading..."

Thats all we need for making a site dynamic. In the next page , we will see a complete working ajax function at a place, which you can use directly without any modifications.

Member Login

Member Login

Not a Member? Sign Up!

Login to comment

Be the first to comment on this topic


<<< Wanna review

Continue >>>