I am facing an issue with the following 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 && 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();
}
In my HTML, I have a select
element that triggers this function to retrieve regions based on the country selected. Despite seeing the request being made in the console, I do not receive any response. The onreadystatechange
function never gets called. However, when I remove xmlhttp.status==200
, the function is invoked but the xmlDoc
object remains as null
and xmlhttp.status==0
. Interestingly, the URL used works fine when accessed independently. Can someone explain why my onreadystatechange
function fails to work and does not return a status of 200?