Skip to content

Commit 969a5e1

Browse files
jblandryfieg
authored andcommitted
Stop ajax responder if instance was destroyed or reinitialized (#245)
1 parent f00efa7 commit 969a5e1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/jquery-ias.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
this.isBound = false;
3131
this.isPaused = false;
3232
this.isInitialized = false;
33+
this.jsXhr = false;
3334
this.listeners = {
3435
next: new IASCallbacks(),
3536
load: new IASCallbacks(),
@@ -186,7 +187,7 @@
186187

187188
self.fire('load', [loadEvent]);
188189

189-
return $.get(loadEvent.url, null, $.proxy(function(data) {
190+
this.jsXhr = $.get(loadEvent.url, null, $.proxy(function(data) {
190191
$itemContainer = $(this.itemsContainerSelector, data).eq(0);
191192
if (0 === $itemContainer.length) {
192193
$itemContainer = $(data).filter(this.itemsContainerSelector).eq(0);
@@ -211,6 +212,8 @@
211212
}
212213
}
213214
}, self), 'html');
215+
216+
return this.jsXhr;
214217
};
215218

216219
/**
@@ -456,6 +459,10 @@
456459
* @public
457460
*/
458461
IAS.prototype.destroy = function() {
462+
try {
463+
this.jsXhr.abort();
464+
} catch (e) {}
465+
459466
this.unbind();
460467

461468
this.$scrollContainer.data('ias', null);

0 commit comments

Comments
 (0)