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 Challenge

I'm not sure what I'm missing here after looking at this two different times with a break in between...

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

2 Answers

I know that I've managed to confuse myself by building something more complicated during the lesson using Jquery

var $ajax = document.getElementById('ajax'); var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4){ $ajax.innerHTML = xhr.responseText; } }; $('#load').click(function(){ xhr.open('GET', 'sidebar.html'); xhr.send(); $('#load').hide();
});

The request.open('GET', 'footer.html'); should go outside the function definition. See the video at around 7:25 for more detail.

The first task should look like the following:

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

I appreciate your response and I thought I tried that BUT....maybe not! Thanks!