title: jQuery/AJAX: How to determine when a host is offline
body: <p>I have a jQuery script that polls my server for new data, but it needs to display an error message if it fails for any reason.</p>
  
  <p>Here is my AJAX request:</p>
  
  <pre><code>$.ajax({
      url: "query.php", // This just runs some MySQL queries and echos the results
      cache: false,
      error: function() {
         $(".status").text("Server is offline.");
         },
      success: function(html) {
         // Everything went fine, append query results to div
         }
  });
  </code></pre>
  
  <p>I've found that if rename query.php so it is unreachable, the error function triggers and the message is displayed. However, if I take the web server offline the error function doesn't trigger.</p>
  
  <p>How can I adapt my code to detect when the host is unreachable?</p>