rails/jquery-ujs — Issue #223: Event ajax:complete does not get triggered 
Author: easychris
Created: 2011-11-18 01:43:14+00:00
State: open

Hey.

Today I upgraded from jquery-rails gem 1.0.16 to 1.0.17. I found out that the "ajax:complete" event is not always triggered anymore.

I prepared a simple Rails app to show the problem:

In application.js I want to trigger all ajax:complete events for existing and new forms (hence the .live call):

```javascript
$(function() {
$('form').live('ajax:complete', function() {
alert('ajax:complete event triggered');
});
});
```

I prepared two sample data-remote=true forms, one page using jQuery 1.6.4, the other 1.7. The ajax call simply returns javascript code to replace the existing form by another form (in real life the new form would contain error messages etc).

```javascript
$('#test_form_container').html(' <%= j (render :partial => 'form') %> ');
```

When using jQuery 1.6.4 the ajax:complete event gets triggered, but unfortunately not using 1.7. I found out that in jquery-ujs the line

```javascript
element.trigger('ajax:complete', [xhr, status]);
```

gets called, but it doesn't trigger any event. I guess because the form to which the ajax event belongs doesn't exist anymore (as it got replaced by the new form). But it should work, as I use the .live event to bind the event to any form-tag. And it does work in 1.6.4.

Any ideas? I tried a couple of hours to find the error, without success. Maybe someone else already has an idea?