JavaScript AJAX Basics (retiring) Programming AJAX Check for the correct ready state

What should I do in this code challenge?!

In the conditional statement you just created, also test to make sure the return status from the server is OK.

app.js
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
    if(xhr.readyState === 4){
    xhr.send();
  }
};
xhr.open('GET', 'sidebar.html');
xhr.send();
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>AJAX with JavaScript</title>
  <script src="app.js"></script>
</head>
<body>
  <div id="main">
    <h1>AJAX!</h1>
  </div>
  <div id="sidebar"></div>
</body>
</html>

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,773 Points

You should check for a status of 200 (OK). See the example on this MDN page for help