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

I can't make the 'sidebar.html' appear.

No error's showing on Console.

<script> var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function() {
  if (xhr.readyState === 4)
  {
    document.getElementById('ajax').innerHTML = xhr.responseText; 
  }

  xhr.open('GET', 'sidebar.html');
  xhr.send();

};

</script>

4 Answers

dragos busuioc
dragos busuioc
24,068 Points
xhr.onreadystatechange = function() { if (xhr.readyState === 4) { document.getElementById('ajax').innerHTML = xhr.responseText; 
} 
};
xhr.open('GET', 'sidebar.html'); //put it outside of onreadystatechange method 
xhr.send(); };//put it outside of onreadystatechange method
dragos busuioc
dragos busuioc
24,068 Points

xhr.onreadystatechange = function() { if (xhr.readyState === 4) { document.getElementById('ajax').innerHTML = xhr.responseText; } xhr.open('GET', 'sidebar.html'); //put it outside of onreadystatechange method xhr.send(); };//put it outside of onreadystatechange method

T SL
PRO
T SL
Pro Student 378 Points

Even the examples in the folder doesn't work though. None of them show sidebar on Chrome on OSX

<script> var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4 ) { document.getElementById('ajax').innerHTML = xhr.responseText; } }; xhr.open('GET', 'sidebar.html'); xhr.send(); </script>