title: Check status of a jQuery ajax request
body: <p>It seems that the success, error, and complete callbacks only fire when the ajax request is able to get some response from the server.</p>
  
  <p>So if I shut down the server the following error callback is not executed and the request fails silently.</p>
  
  <pre><code>$.ajax({
    type: "GET",
    url: "http://localhost:3000/",
    dataType: "script",
    success: function() {
      alert("success");
    },
    error: function() {
      alert("error");
    }
  });
  </code></pre>
  
  <p>What's the best way to throw an error when the server can't be reached at all.</p>
  
  <p>Edit - From what I've tried and read it appears that jQuery's built in error handling doesn't work with JSONP, or dataType: "script". So I'm going to try setting a manual timeout.</p>
  
  <p>Edit - Did a little more research and it looks like not only does the ajax error callback not work, but you can't abort an ajax request with dataType script or jsonp, and those requests ignore the timeout setting.</p>
  
  <p>There is an alternative - the jquery-jsonp plugin, but it uses hidden iframes which I'd rather avoid. So I've settled on creating a manual timeout as suggested below. You can't abort the request if it times out, which means the script may still load even after the timeout, but at least something will fire if the server is unavailable.</p>