From 98dd98690fdd07c5a65051e241bc8dfbaa4f3270 Mon Sep 17 00:00:00 2001 From: Luis Felipe Colle da Luz Date: Sun, 3 Jul 2016 11:21:57 -0300 Subject: [PATCH] Changed ajax:complete callback to run even if the element was removed from the page --- src/rails.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rails.js b/src/rails.js index 9e192a2e..8cf43015 100644 --- a/src/rails.js +++ b/src/rails.js @@ -157,7 +157,11 @@ element.trigger('ajax:success', [data, status, xhr]); }, complete: function(xhr, status) { - element.trigger('ajax:complete', [xhr, status]); + if (element.parents('html').length > 0) { + element.trigger('ajax:complete', [xhr, status]); + } else { + $(document).trigger('ajax:complete', [xhr, status]); + } }, error: function(xhr, status, error) { element.trigger('ajax:error', [xhr, status, error]);