url = "http://localhost/xml.php?type=xml";
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader('Content-Type', 'application/xml');
xmlhttp.send(null);
}
else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp) {
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader('Content-Type', 'application/xml');
xmlhttp.send();
}
}
alert(xmlhttp.responseXML); //returns null
XML file
<?xml version="1.0" encoding="UTF-8" ?>
<main>
<food>
<type>6</type>
<region>5676</region>
</food>
<food>
<type>6</type>
<region>5676</region>
</food>
</main>
Anyone has idea why xmlhttp.responseXML
is returning as null?