From cfb66f5e4f71a56c46a6890c5dde4b7f24f11fa8 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 27 Mar 2016 15:44:40 -0400 Subject: [PATCH] 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 --- src/js/select2/data/ajax.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js/select2/data/ajax.js b/src/js/select2/data/ajax.js index 92b9e1dd..3309298f 100644 --- a/src/js/select2/data/ajax.js +++ b/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' });