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

I can't make the 'sidebar.html' appear.

No error's showing on Console.

<script> var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function() {
  if (xhr.readyState === 4)
  {
    document.getElementById('ajax').innerHTML = xhr.responseText; 
  }

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

};

</script>

4 Answers

dragos busuioc
dragos busuioc
24,908 Points
xhr.onreadystatechange = function() { if (xhr.readyState === 4) { document.getElementById('ajax').innerHTML = xhr.responseText; 
} 
};
xhr.open('GET', 'sidebar.html'); //put it outside of onreadystatechange method 
xhr.send(); };//put it outside of onreadystatechange method
dragos busuioc
dragos busuioc
24,908 Points

xhr.onreadystatechange = function() { if (xhr.readyState === 4) { document.getElementById('ajax').innerHTML = xhr.responseText; } xhr.open('GET', 'sidebar.html'); //put it outside of onreadystatechange method xhr.send(); };//put it outside of onreadystatechange method

T SL
PLUS
T SL
Courses Plus Student 378 Points

Even the examples in the folder doesn't work though. None of them show sidebar on Chrome on OSX

Christopher Gjelten
Christopher Gjelten
2,305 Points

<script> var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4 ) { document.getElementById('ajax').innerHTML = xhr.responseText; } }; xhr.open('GET', 'sidebar.html'); xhr.send(); </script>