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 trialMUZ140017 Sijabuliso Dube
8,440 PointsChallenge Task 2 of 2 Add the code to send the AJAX request.
guys I am stuck please help
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>
4 Answers
Michael Geatz
6,093 PointsYou need to send a request to the server. Try adding this:
request.send();
Cameron Mosser
7,102 Pointsvar request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === 4) {
document.getElementById("footer").innerHTML = request.responseText;
}
};
request.open("GET", "footer.html");
request.send(); <!-- this is where you need to place your code to send the AJAX request -->
Simone Beaver
Full Stack JavaScript Techdegree Graduate 15,720 Pointsif you opened the request, then send the request but without any parameters. Hope this helps
Alan Lane
9,156 Pointsvar request = new XMLHttpRequest(); request.onreadystatechange = function () { if (request.readyState === 4) { document.getElementById("footer").innerHTML = request.responseText; } }; request.open('GET', 'footer.html'); function sendAJAX() { request.send(); }
This is what I posted, but its asking "Did you call send() on the request object?" I thought that is what I did? Any suggestions?