Skip to content

Commit 2a9ebd8

Browse files
authored
Merge pull request tetranz#86 from martijnhartlief/ajax-abort
Abort previous AJAX request
2 parents 623fb50 + bad2069 commit 2a9ebd8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Resources/public/js/select2entity.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(function( $ ) {
22
$.fn.select2entity = function (options) {
33
this.each(function () {
4+
var request;
5+
46
// Keep a reference to the element so we can keep the cache local to this instance and so we can
57
// fetch config settings since select2 doesn't expose its options to the transport method.
68
var $s2 = $(this),
@@ -39,7 +41,12 @@
3941
}
4042
} else {
4143
// no caching enabled. just do the ajax request
42-
$.ajax(params).fail(failure).done(success);
44+
if (request) {
45+
request.abort();
46+
}
47+
request = $.ajax(params).fail(failure).done(success).always(function () {
48+
request = undefined;
49+
});
4350
}
4451
},
4552
data: function (params) {

0 commit comments

Comments
 (0)