title: jQuery.ajax() - How to handle timeouts best?
body: <p>I'm wondering, what's the best way to handle timeouts with <strong>jQuery.ajax()</strong>. That's my solution at the moment: If an timeout occurs the page will be reloaded and the script gets another chance to load the data within it's given timeframe.</p>
  
  <p><strong>Problem</strong>: if "get_json.php" (example below) is really not available, it will become an endless reloading-loop. 
  Possible solution: adding a counter and cancel after $x reloads.</p>
  
  <p><strong>Question 1</strong>:
  How to handle the timeout error best?</p>
  
  <p><strong>Question 2</strong>:
  What's your recommended timeframe for a timeout and why?</p>
  
  <p><strong>Code</strong>:</p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: "get_json.php",
      timeout: 500,
      dataType: "json",
      success: function(json) {
          alert("JSON loaded: " + json);
      },
      error: function(request, status, err) {
          if (status == "timeout") {
              // timeout -&gt; reload the page and try again
              console.log("timeout");
              window.location.reload();
          } else {
              // another error occured  
              alert("error: " + request + status + err);
          }
      }
  });
  </code></pre>
  
  <p>Thanks in advance!</p>