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 trialDaniel Toma
2,370 PointsOpen XMLHttpRequest with two arguments - code not working
I can't see what I'm doing wrong here. The task was to add the code to open the AJAX request using GET and pointing to 'footer.html'. I added the line of code below the IF statement, but I get the 'Bummer!' I don't know what else to try.
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === 4) {
document.getElementById("footer").innerHTML = request.responseText;
}
request.open('GET', 'footer.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>
3 Answers
Thayer Y
29,789 Pointsjust move the line outside the function, after the last curly bracket.
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === 4) {
document.getElementById("footer").innerHTML = request.responseText;
}
request.open('GET', 'footer.html');
};
request.open('GET', 'footer.html'); // move it here
Jon Schiedermayer
7,709 PointsI was stuck on exact same question. Thayer Y 's solution worked for me.
Daniel Toma
2,370 PointsThat was it! Thanks, Thayer Y!