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 AJAX Concepts A Simple AJAX Example

Ajax simple lesson not working for me. What am I doing wrong?

Wouldn't hurt to zoom in the example videos a bit.. Squinting isn't much fun lol. Otherwise, I've been up and down this trying to type it out to follow along. Button doesn't work for me.. I'm using the workspace for this. Just wondering what I did, or if it's something server side. I'm just trying to type what you typed.

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

</script>

1 Answer

Patrick Koch
Patrick Koch
40,496 Points

It seems like there might be an issue with the script you provided. It looks like there's a syntax error in the xhr.open line. The string inside the open function should be enclosed in single or double quotes, but in your code, there's a mix of single and double quotes.

Here's the corrected version:

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

Make sure to replace the incorrect quotes with the correct ones. This should resolve the issue you're facing with the button not working. If the problem persists, please check for any error messages in the console or provide more details about the specific error you're encountering.