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

Add the code to send the AJAX request.

```var 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(); send.AJAX(); }

What am I missing? It keeps saying "Bummer. Did you call send() on the request object?

app.js
var 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();
  send.AJAX();
}   
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>

2 Answers

Jazz Jones
Jazz Jones
8,535 Points
request.open('GET', 'footer.html');
request.send();

^^ is all you need to complete the challenge. I'm not sure what you were trying to do with your sendAJAX function as there isn't a .AJAX method in vanilla javascript. Remember AJAX is a technique, not an actual built in method and requires 4 things:

  1. XMLHttpRequest Object
  2. Callback function
  3. Open method to open a request
  4. Send method to send the request.

Hope this helps :)

Thank you Jazz Jones. I should have taken a break from the problem and came back with a fresh set of eyes. Lol. Thank you for posting a reminder of the AJAX technique requirements.

Leandro Botella Penalva
Leandro Botella Penalva
17,618 Points

Hi Terri,

I don't know where did you get that send.AJAX() function since it doesn't exist. Also, you don't need to create a function. Call the request send method after the request is opened like this:

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

Thank you Leandro Penalva. I had been working on a solution for a couple of hours. I am a newbie. I was trying just about everything. I guess I should have taken a break. Lol.