I'm trying to find out why the android browser won't load and/or display my XML data. This javascript works fine on computer browsers (FF, IE, Safari, Chrome, Opera) and even in iPhone's Safari, but when I view the same page in my android's browser, nothing is displayed...it' s just blank. Is it a javascript bug in the android browser?
I wasn't sure if this should be posted in "Mobile Development" or here in "Javascript/Ajax/DHTML" so here it is...but thanks anyway for any insight you may have!
Code:
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(dname) {
var xmlDoc;
if (window.XMLHttpRequest) {
xmlDoc = new window.XMLHttpRequest();
xmlDoc.open("GET",dname,false);
xmlDoc.send("");
return xmlDoc.responseXML;
}
// IE 5 and IE 6
else if (ActiveXObject("Microsoft.XMLDOM")) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(dname);
return xmlDoc;
}
alert("Error loading document");
return null;
}
</script>
</head>
<body>
<script type="text/javascript">
xmlDoc = loadXMLDoc("news.xml");
x = xmlDoc.getElementsByTagName('article');
for (i=0; i<x.length; i++) {
document.write("<span class='h2'>" + x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue + "</span><br />");
document.write("<span class='gray'>" + x[i].getElementsByTagName("date")[0].childNodes[0].nodeValue + "</span><br /><br />");
document.write(x[i].getElementsByTagName("text")[0].childNodes[0].nodeValue + "<hr />");
}
</script>
</body>
</html>
Comment