eldarion / eldarion-ajax

a library for adding declarative ajax functionality to your website
BSD 3-Clause "New" or "Revised" License
758 stars 153 forks source link

Triggering of success and error events #24

Closed stevenmhunt closed 11 years ago

stevenmhunt commented 11 years ago

This is a suggestion/enhancement that didn't warrant a fork and merge and doesn't fix a bug or error. At the end of the processData and processError functions, you trigger events that can be used to notify the application when data is processed or and error occurs. My suggestion is to modify the code to trigger the event on the element itself instead of document. The code currently looks like this:

$(document).trigger('bootstrap-ajax:success', [data, $el]);

I would recommend that it look like this:

$($el).trigger('bootstrap-ajax:success', [data]);

That way when I bind to it I can get events on my specific form or anchor that's posting back like this:

$("#myform").on("bootstrap-ajax:success", function(e, data) {
   ....
});

The current approach is functional, but I believe that the approach I am presenting is more in the spirit of jQuery and bootstrap.

Thank you for your consideration.

paltman commented 11 years ago

@stevenmhunt good tip