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 trialMatthew Smart
12,567 PointsA Simple AJAX EXAMPLE
On the video for a simple ajax example. i have written the same code, but it does not do anything at all.
<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>
its just showing the h1
2 Answers
Matthew Ludwigs
11,197 PointsHey Matthew,
I am not sure if this will help or not, but try making the "D" in Document that is inside your if statement lowercase so it reads:
if (xhr.readyState === 4) {
document.getElementById('ajax').innerHTML = xhr.responseText;
}
If you open your JS console in the browser on your page you may see a TypeError about how undefined is not a function. Basically Document is the typeof function, and document is the typeof of object. You can even check by typing in your console:
typeof Document
And hit enter, then:
typeof document
and hit enter. JS is case sensitive, and I know from personal experiences that many errors are related to something small like capitalization or a missing semi-colon.
I hope this helps!
Matt
Nick Ocampo
15,661 PointsTry writing document with a lower-case d and see if that works.