title: onreadystatechange function is not working in AJAX
body: <p>as far as XMLHttpRequest() Object is concerned, it is fine, the problem is with <strong>onreadystatechange</strong> for example if I put my code this way, it works perfect.</p>
  
  <pre><code>function process(){
      var xmlHttp = new XMLHttpRequest();
  
      if(xmlHttp){
          xmlHttp.onreadystatechange = function(){
              theD = document.getElementById("theD");
              if(xmlHttp.readyState == 1){
                  theD.innerHTML += "Status 1: Server connection established ! &lt;br/&gt;";
              }
              else if(xmlHttp.readyState == 2){
                  theD.innerHTML += "Status 2: Request recieved ! &lt;br/&gt;";
              }
              else if(xmlHttp.readyState == 3){
                  theD.innerHTML += "Status 3: Processing Request ! &lt;br/&gt;";
              }
              else if(xmlHttp.readyState == 4){
  
                  if(xmlHttp.status == 200){
                      var text = xmlHttp.responseText;
                      theD.innerHTML += "Status 4: Processing Request ! &lt;br/&gt;";
                      theD.innerHTML += text;
                  }
                  else{
                      alert("Something is wrong !");
                  }
              }
          };
          xmlHttp.open("GET", "hello.txt", true);
          xmlHttp.send();
      }
  }
  </code></pre>
  
  <p>but if I make a function of <strong>handleServerResponse()</strong></p>
  
  <pre><code>function handleServerResponse(){
      theD = document.getElementById("theD");
      if(xmlHttp.readyState == 1){
          theD.innerHTML += "Status 1: Server connection established ! &lt;br/&gt;";
      }
      else if(xmlHttp.readyState == 2){
          theD.innerHTML += "Status 2: Request recieved ! &lt;br/&gt;";
      }
      else if(xmlHttp.readyState == 3){
          theD.innerHTML += "Status 3: Processing Request ! &lt;br/&gt;";
      }
      else if(xmlHttp.readyState == 4){
  
          if(xmlHttp.status == 200){
              var text = xmlHttp.responseText;
              theD.innerHTML += "Status 4: Processing Request ! &lt;br/&gt;";
              theD.innerHTML += text;
          }
          else{
              alert("Something is wrong !");
          }
      }
  }
  </code></pre>
  
  <p>And call it like</p>
  
  <pre><code>xmlHttp.onreadystatechange = handleServerResponse();
  </code></pre>
  
  <p>It doesn't work. Please point it if I'm wrong.</p>