JavaScript AJAX Basics (retiring) Programming AJAX Create a callback

why does the editor not accept xhr.onreadystatechange(() => { }); ?

Does the editor not like anonymous functions?

I also tried xhr.onreadystatechange(function() { }); and it didn't like that either

var xhr = new XMLHttpRequest();
  function() {
);'GET', 'sidebar.html');
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>AJAX with JavaScript</title>
  <script src="app.js"></script>
  <div id="main">
  <div id="sidebar"></div>

1 Answer

Hi Liam,

It's because you are trying to pass the anonymous function to xhr.onreadystatechange, as if it's a parameter.

You need to assign the function to xhr.onreadystatechange using =

For example:

xhr.onreadystatechange = function(){};

Hope this helps :)

Thank you very much.