title: jQuery ajax request - prevent overlapping
body: <p>I'm calling a function using the jQuery ajax function for calling a webservice in an interval of milliseconds. If one of the first request is slower they are overflapping and the success function will do work with an old requests response.</p>
  
  <p>Here is my ajax calling function:</p>
  
  <pre><code>function runRequest(url, request, token, handleSuccess, handleError) {
      $.ajax({
          url: url,
          type: "POST",
          data: JSON.stringify(request),
          headers: {
              "Authorization": "Basic " + btoa(/* ... */),
              "Content-Type": "application/json"
          },
          success: function (data, status, xhr) {
              handleSuccess(data);
          },
          error: function (xhr, status, error) {
              handleError(xhr);
          }
      });
  }
  </code></pre>
  
  <p>How to prevent that? I tried to save the time on creation of a request, managed that time to the success and error function to check it if the response is incoming but it won't work..</p>
  
  <p>Synchronized ajax request is no option.. :/</p>