Sfoglia il codice sorgente

Attempt to detect aborted requests

The error handler should not be raised if a request is aborted while
another one is sent out. This attempts to detect those cases by
handling the case where the error was raised and the request has a
status code of 0, which should either mean we're in offline mode or
the request was aborted.

This closes https://github.com/select2/select2/issues/4205
Kevin Brown 9 anni fa
parent
commit
cfb66f5e4f
1 ha cambiato i file con 6 aggiunte e 0 eliminazioni
  1. 6 0
      src/js/select2/data/ajax.js

+ 6 - 0
src/js/select2/data/ajax.js

@@ -80,6 +80,12 @@ define([
 
 
         callback(results);
         callback(results);
       }, function () {
       }, function () {
+        // Attempt to detect if a request was aborted
+        // Only works if the transport exposes a status property
+        if ($request.status && $request.status === '0') {
+          return;
+        }
+
         self.trigger('results:message', {
         self.trigger('results:message', {
           message: 'errorLoading'
           message: 'errorLoading'
         });
         });