0

Uncaught TypeError: Cannot set property 'innerHTML' of null at XMLHttpRequest.xhttp.onreadystatechange error and maybe you can find how to fix it?

 <head>
 <meta charset="utf-8">
 <title></title>
  </head>
 <body>
   <script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = JSON.parse(xhttp.responseText);
var times = response.times;
var output = '';
for (var i = 0; i < times.length; i++) {
output += '<li>'+times[i].diena+'</li>';
  }
  document.getElementById('times').innerHTML = output;
  }
 };
   xhttp.open("GET", "time.json", true);
   xhttp.send();
  </script>
 </body>
</html>

1 Answers1

-1

Create <div id="times"></div> inside the Body tag then test your code.

Hossein Zare
  • 532
  • 2
  • 16