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

Why doesn't my preview do anything?

I have the exact code shown, have looked it up and down for typos... nothing happens. I even did the next part where we check the console log and (index):16 XHR finished loading: GET "http://port-80-dgb2wcpndw.treehouse-app.com/sidebar.html". shows up like shown in the video but the page doesn't actually do anything..?

1 Answer

I just clicked the button and got the output from sidebar.html. I saw some similar code that included a test of status, so something like

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
    if(xhr.readyState === 4 && xhr.status === 200) {
   document.getElementById('ajax').innerHTML = xhr.responseText;
//console.log('i is here:'+xhr.responseText);
    }
};
xhr.open('GET', 'sidebar.html');
xhr.send();