title: XMLHttpRequest onreadystatechange called multiple times
body: <p>I am implementing a login system in php and using ajax requests.</p>
  
  <p>this is my request</p>
  
  <pre><code>hr.open("POST", url, true);
  hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  
  hr.onreadystatechange = function() {
  
      var return_data = hr.responseText;
      if(hr.readyState == 4 &amp;&amp; hr.status == 200) {
          alert('is logged');
      }else if (hr.status == 400){
          alert('is not logged');
      }
  }
  
  
  hr.send(vars); // Actually execute the request
  </code></pre>
  
  <p>but when i get the response back the browser launches various alerts. Can anyone help how to fix this?</p>