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

[SOLVED] Am getting "undefined" after I click the buuton

When we preview in Workspaces, is the code supposed to work or should I set up a local server? I've checked my code 3 times and keep getting, undefined, after clicking the button.

    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () { 
      if (xhr.readyState === 4) {
        document.getElementById('ajax').innerHTML = xhr.repsonseText;
      }
    };
    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" onclick="sendAJAX()">Bring it!</button>
          </div>

Edited for solved

1 Answer

Please ... someone remind me that as soon as you post a question, you find the problem when you give it another look! repsonseText is supposed to be responseText! Got it, now!

Made the same mistake as you with a slight difference. reponseText instead of responseText Thanks for helping me out!