title: Javascript: Check if server is online?
body: <p>What's the fastest way to check if my server is online via JavaScript?</p>
  
  <p>I've tried the following AJAX:</p>
  
  <pre><code>function isonline() {
      var uri = 'MYURL'
      var xhr = new XMLHttpRequest();
      xhr.open("GET",uri,false);
      xhr.send(null);
      if(xhr.status == 200) {
          //is online
          return xhr.responseText;
      }
      else {
          //is offline
          return null;
      }   
  }
  </code></pre>
  
  <p>The problem is, it never returns if the server is offline. How can I set a timeout so that if it isn't returning after a certain amount of time, I can assume it is offline?</p>