浏览代码

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 年之前
父节点
当前提交
cfb66f5e4f
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      src/js/select2/data/ajax.js

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

@@ -80,6 +80,12 @@ define([
 
         callback(results);
       }, 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', {
           message: 'errorLoading'
         });