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 trialMichael Dinnall
6,730 Pointsopen 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');
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === 4) {
document.getElementById("footer").innerHTML = request.responseText;
}
};
<!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
Treehouse TeacherHi 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!
Michael Dinnall
6,730 PointsMichael Dinnall
6,730 PointsThank!!! Now i get why we save the initial request in a variable.