rails / jquery-ujs

Ruby on Rails unobtrusive scripting adapter for jQuery
MIT License
2.6k stars 508 forks source link

events for data-remote requests not firing #406

Open jogaco opened 9 years ago

jogaco commented 9 years ago

I'm using $rails.handleRemote to run remote calls on dynamically created remote links. However, even though I attach these links to the document, none of the events ajax:complete, ajax:success, ajax:error are fired. My controller returned javascript and updated the page accordingly but I changed it to return html content it so I can better handle user input errors and so on in the ajax:success and suchlike events.

I tried adding

    $(document).delegate('a[data-remote]', 'confirm:complete', function(e, answer) {
        console.log('confirmed!', answer);
    }).delegate('a[data-remote]', 'ajax:before', function() {
        console.log('sending!');
    }).delegate('a[data-remote]', 'ajax:complete', function() {
        console.log('complete!');
    }).delegate('a[data-remote]', 'ajax:success', function() {
        console.log('success!');
    });

but nothing shows up.

No javascript errors are shown on the console either.

During debugging I have seen the line is run, but the event is not fired!

success: function(data, status, xhr) {
            element.trigger('ajax:success', [data, status, xhr]);
          },

Any tip to narrow down the problem?

ericdfields commented 9 years ago

Hi. Just saw this. I wonder if it's related to what I just filed: #408