title: Ajax xmlhttp.onreadystatechange function
body: <p>I have this code:</p>
  
  <pre><code>function loadRegions()
  {
      var xmlhttp;
  
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
           xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      xmlhttp.onreadystatechange=function()
      {
          if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
          {
             alert("Ready:"+xmlhttp.status);
             xmlDoc=xmlhttp.responseXML;
             x=xmlDoc.getElementsByTagName("region");
             alert(x[0]);
             alert(x[1]);
         }
     }
  
     var ctrcode = frm.elements['countrycode'];
     xmlhttp.open("GET","http://mydomain.gr/regionslist.php?countrycode="+ctrcode.value,true);
     xmlhttp.send();
  }
  </code></pre>
  
  <p>I have a <code>select</code> item in my HTML and when someone selects an item then this function is called to get the regions of this country. I can see from my console that the request is done, but the response is never gotten. My <code>onreadystatechange</code> function is never called. When I delete <code>xmlhttp.status==200</code> then the function is called but the <code>xmlDoc</code> object is <code>null</code> and <code>xmlhttp.status==0</code>. The URL I use works if I call it alone. Why does my <code>onreadystatechange</code> function not work and why does it not return status 200?</p>