I am trying to parse an RSS feed using javascript, and I recently ran into a problem opening an XML file from both localhost and web server (I always access my local files using http:// keyword all the time when I work on localhost). I received XML status 0 instead of status 200 (established) in all browser. The problem only occurs when I try to open an XML file hosted on a server. Here is what I have :
if(window.ActiveXObject)//IE
xml_req = new ActiveXObject("Microsoft.XMLHTTP");
else if(window.XMLHttpRequest)
xml_req = new XMLHttpRequest();
else alert('no ajax support');
xml_req = new XMLHttpRequest();
var url = "http://www.something.net/rss.xml";
xml_req.open("GET", url, true);
xml_req.onreadystatechange = function(){
if(xml_req.readyState == 4){
if(xml_req.status == 200){
if(xml_req.responseText != null)
.....//DO STUFF
else{
alert("Error");
return false;
}
}
else{
//THIS IS WHERE THE ERROR OCCURS,STATUS=0 INSTEAD OF 200
alert("XML Status = " + xml_req.status + xml_req.statusText);}
}
}
Everything works fine when I open an XML local file that is not hosted on the server. For instance, the code below opens the rss file within the localhost just fine :
var url = "rssLocalhost.xml";
xml_req.open("GET", url, true);
Please help! Would appreciate any suggestions from anybody out there. Thanks!