P
P
Pavel_Proca2017-07-03 13:22:01
JavaScript
Pavel_Proca, 2017-07-03 13:22:01

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

1 answer(s)
V
Vladimir, 2017-07-03
@djQuery

Try to dig in this direction.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question