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 A Simple AJAX Example

Stuck, I've checked everything and It's still not working.

Heya'.

I can't seem to wrap my head around to why this is not working? Can anyone please help me with what the heck is going wrong in this code?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/main.css">
  <title>AJAX with JavaScript</title>
  <script>

  // Step 1 // - Create XMLHTTP Request object.
  var xhr = new XMLHttpRequest();

  // Step 2 // - Create callback function. 
  //this is the code that is going to run when the server respons to your request.
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) {
      document.getElementById('ajax').innerHTML = xhr.responseText;
    }
  };

  // Step 3 // - Open a request.
  xhr.open('GET', 'sidebar.html');


  //Step 4 // - Send Request 
  xhr.send();

  </script>
</head>
<body>
  <div class="grid-container centered">
    <div class="grid-100">
      <div class="contained">
        <div class="grid-100">
          <h1>Bring on the AJAX</h1>
          <ul id="ajax">

          </ul>
        </div>
      </div>
    </div>
  </div>



</body>
</html>
Adam Beer
Adam Beer
11,314 Points

This is looks good. Maybe you don't saved the file before check

1 Answer

Sean T. Unwin
Sean T. Unwin
28,690 Points

Missing the button that when pressed calls the the function which xhr.send(); is wrapped in. The function is missing as well.

Check the video from the 9:50 mark.

Fixed it thanks!