Skip to content

Commit 98dd986

Browse files
committed
Changed ajax:complete callback to run even if the element was removed from the page
1 parent 5e49774 commit 98dd986

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/rails.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@
157157
element.trigger('ajax:success', [data, status, xhr]);
158158
},
159159
complete: function(xhr, status) {
160-
element.trigger('ajax:complete', [xhr, status]);
160+
if (element.parents('html').length > 0) {
161+
element.trigger('ajax:complete', [xhr, status]);
162+
} else {
163+
$(document).trigger('ajax:complete', [xhr, status]);
164+
}
161165
},
162166
error: function(xhr, status, error) {
163167
element.trigger('ajax:error', [xhr, status, error]);

0 commit comments

Comments
 (0)