JavaScript AJAX Basics (retiring) AJAX Concepts A Simple AJAX Example

Ben Ahlander
Ben Ahlander
7,528 Points

Why is my button not working?

<!DOCTYPE html>
  <meta charset="utf-8">
  <link href='//' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/main.css">
  <title>AJAX with JavaScript</title>
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
      if(xhr.readyState === 4) {
        document.getElementById('ajax').innerHTML = xhr.responseText;
    }; ('GET', 'sidebar.html');
    function sendAJAX() {
      document.getElementById('load')style.display = "none";

  <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()">Bringit!</button>
          <div id="ajax">


1 Answer

Huy Bui
Huy Bui
14,092 Points

Hey Ben,

Looks like the problematic code is in your 'sendAJAX' function declaration. Just need to add a period to fix the method chaining:

document.getElementById('load').style.display = "none";

Hope this helps,