title: jQuery: Handle fallback for failed AJAX Request
body: <p>Can jQuery provide a fallback for failed AJAX calls? This is my try:</p>
  
  <pre><code>function update() {
      var requestOK = false;
  
      $.getJSON(url, function(){
          alert('request successful');
          requestOK = true;
      });
  
      if (!requestOK) {
          alert('request failed');
      }
  }
  </code></pre>
  
  <p>Unfortunately, even if the callback function of the $.getJSON() method is called, i get the message 'request failed', before the callback function has the opportunity to set the requestOK variable. I think it's because the code runs in parallel. Is there a way to handle such situations? I thought about chaining or some way of waiting for the AJAX request, including its callback function. But how? Does anyone know how to do that?</p>