Skip to content

Commit e749898

Browse files
committed
Fix abort with JSONP
We now check that the `abort` method actually exists before aborting the request, as JSONP does not include the `abort` method because a JSONP request technically cannot be aborted. This closes select2#3217.
1 parent a8e6cbc commit e749898

5 files changed

Lines changed: 23 additions & 15 deletions

File tree

dist/js/select2.full.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,8 +1668,6 @@ S2.define('select2/selection/allowClear',[
16681668
};
16691669

16701670
AllowClear.prototype._handleClear = function (_, evt) {
1671-
console.log(arguments);
1672-
16731671
// Ignore the event if it is disabled
16741672
if (this.options.get('disabled')) {
16751673
return;
@@ -3275,8 +3273,12 @@ S2.define('select2/data/ajax',[
32753273
var matches = [];
32763274
var self = this;
32773275

3278-
if (this._request) {
3279-
this._request.abort();
3276+
if (this._request != null) {
3277+
// JSONP requests cannot always be aborted
3278+
if ($.isFunction(this._request.abort)) {
3279+
this._request.abort();
3280+
}
3281+
32803282
this._request = null;
32813283
}
32823284

dist/js/select2.full.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,8 +1668,6 @@ S2.define('select2/selection/allowClear',[
16681668
};
16691669

16701670
AllowClear.prototype._handleClear = function (_, evt) {
1671-
console.log(arguments);
1672-
16731671
// Ignore the event if it is disabled
16741672
if (this.options.get('disabled')) {
16751673
return;
@@ -3275,8 +3273,12 @@ S2.define('select2/data/ajax',[
32753273
var matches = [];
32763274
var self = this;
32773275

3278-
if (this._request) {
3279-
this._request.abort();
3276+
if (this._request != null) {
3277+
// JSONP requests cannot always be aborted
3278+
if ($.isFunction(this._request.abort)) {
3279+
this._request.abort();
3280+
}
3281+
32803282
this._request = null;
32813283
}
32823284

dist/js/select2.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/select2/data/ajax.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ define([
4343
var matches = [];
4444
var self = this;
4545

46-
if (this._request) {
47-
this._request.abort();
46+
if (this._request != null) {
47+
// JSONP requests cannot always be aborted
48+
if ($.isFunction(this._request.abort)) {
49+
this._request.abort();
50+
}
51+
4852
this._request = null;
4953
}
5054

0 commit comments

Comments
 (0)