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 Correct Ready State Code Challenge

The task is to call the div tag "sidebar" and display it. I copied the code verbatim from my Workspace but it doesn't work. Can anyone please help?

var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function() {

   if (xhr.readyState === 4 && xhr.status === 200) {
    }

};
xhr.open('GET', 'sidebar.html');

  function sendAJAX() {

    xhr.send();
    document.getElementById('sidebar').style.display = 'none';
  }

1 Answer

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Hi Jason Larkin

You need to select the sidebar element within the callback function and set the sidebar's innerHTML property to the server's response.

You don't need the sendAJAX() function or this line of code

    document.getElementById('sidebar').style.display = 'none';

Thanks Dave, it worked.

Dave McFarland
Dave McFarland
Treehouse Teacher

Great! Glad it worked out Jason.