JavaScript AJAX Basics (retiring) AJAX Concepts Finish the AJAX Request

Ben Joyce
Ben Joyce
420 Points

Even if I am typing things correctly I get bummer message

I think something does not work.

app.js
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
  if (request.readyState === 4) {
    document.getElementById("footer").innerHTML = request.responseText;
  }
  request.open('GET','Footer.html')
};
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>AJAX with JavaScript</title>
  <script src="app.js"></script>
</head>
<body>
  <div id="main">
    <h1>AJAX!</h1>
  </div>
  <div id="footer"></div>
</body>
</html>

1 Answer

Kevin Kenger
Kevin Kenger
31,638 Points

Hey Ben,

Right now I see two issues in your JS code. The first is that you've got your open request inside of the onreadystatechange function, and the second is the capitalization of the footer.html file you're requesting.

So fixing those should make the code look more like this:

var request = new XMLHttpRequest();
request.onreadystatechange = function () {
  if (request.readyState === 4) {
    document.getElementById("footer").innerHTML = request.responseText;
  }
}
request.open('GET','footer.html');