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

jocelin queau
jocelin queau
4,846 Points

Ajax error : You need to specify the request object and use the open() method on it.

i don't know what i'm doing wrong ..

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

Adam Beer
Adam Beer
11,269 Points

You are very close. Put it under the function. Hope this help.

jocelin queau
jocelin queau
4,846 Points

thanks a lot ! i passed it thank to your help