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

Why doesn't my button work?

I have followed the steps in the video correctly, yet my button still doesn't work as expected. why?

 <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <link href='//fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/main.css">
  <title>AJAX with JavaScript</title>
  <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>
</head>
<body>
  <div class="grid-container centered">
    <div class="grid-100">
      <div class="contained">
        <div class="grid-100">
          <div class="heading">
            <h1>Bring on the AJAX</h1>
            <button id="load" onlick="sendAJAX();">Bring it!</button>
          </div>
          <div id="ajax">

          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

I have included my code

Yes, I have included everything. Actually it works perfectly without the button. But when I add the button, clicking the button doesn't display the expected text

Yes

Daniel Turato
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Turato
Java Web Development Techdegree Graduate 30,124 Points

Can you take a snapshot of your workspace? You can do this by clicking the camera button on the top right of your workspace. Once done, copy and paste the link of the snapshot here so I can see

I am having the same problem

2 Answers

Kevin Gates
Kevin Gates
15,053 Points

You put onlick() instead of onclick(). You're missing the "c" in "click".

horacinis
horacinis
4,824 Points

<button id="load" onlick="sendAJAX();">

Yeah, you put "onlick" instead of "onclick" but I see another mistake, you put a semicolon at the end of "sendAJAX();", remove that semicolon so it its "sendAJAX()", without the semicolon.