Answer the question
In order to leave comments, you need to log in
How to allow XML loading in Google Chrome?
I'm trying to display data from XML in an HTML file, but it only works in Mozilla Firefox. I can't figure out what the problem is. Here is what the console displays in Google Chrome . I did everything like in this video.
And here is my code:
<!DOCTYPE html>
<html>
<head>
<title>Asd 2</title>
</head>
<body>
<script type="text/javascript">
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = ActiveXObject("Microsoft.XMLHTTP");
};
xmlhttp.open("GET", "asd2.xml", false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table>");
document.write("<tr><th>Roll</th><th>Marks</th></tr>");
var x=xmlDoc.getElementsByTagName("roll");
for (var i = 0; i < x.length; i++) {
document.write("<tr><td>");
document.write(xmlDoc.getElementsByTagName("roll")[i].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(xmlDoc.getElementsByTagName("marks")[i].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table");
</script>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<te>
<student>
<roll>1</roll>
<name>XYZ</name>
<marks>48%</marks>
</student>
<student>
<roll>2</roll>
<name>XYZ</name>
<marks>48%</marks>
</student>
<student>
<roll>3</roll>
<name>XYZ</name>
<marks>48%</marks>
</student>
<student>
<roll>4</roll>
<name>XYZ</name>
<marks>48%</marks>
</student>
</te>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question