Skip to content

Commit bad2069

Browse files
author
Martijn Hartlief
committed
Abort previous AJAX request
1 parent 6bc88a8 commit bad2069

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
$(document).ready(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),
@@ -38,7 +40,12 @@ $(document).ready(function () {
3840
}
3941
} else {
4042
// no caching enabled. just do the ajax request
41-
$.ajax(params).fail(failure).done(success);
43+
if (request) {
44+
request.abort();
45+
}
46+
request = $.ajax(params).fail(failure).done(success).always(function () {
47+
request = undefined;
48+
});
4249
}
4350
},
4451
data: function (params) {

0 commit comments

Comments
 (0)