Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Michael Dinnall
Michael Dinnall
6,730 Points

open the AJAX request using the GET method and pointing to the 'footer.html' file.

Here is what I did, I'm not to sure what im doing wrong

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

app.js
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
  if (request.readyState === 4) {
    document.getElementById("footer").innerHTML = request.responseText;
  }
};
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

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're trying to use a variable you never declared. The variable xhr is not declared anywhere in your code, but you're trying to open it. However, you've got a perfectly good request variable all set up! So here's the line you need to change (at least for step 1):

request.open('GET','footer.html');

Hope this helps! :sparkles:

Michael Dinnall
Michael Dinnall
6,730 Points

Thank!!! Now i get why we save the initial request in a variable.