1 $(document).on('ajax:error', function(e, xhr, status, error) {
2 var errorMessage = '' + status + ': ' + error;
3 // $btn is the element (button/link) that initiated the failed request.
4 var $btn = $(e.target);
5 // Populate some elements with the error text (e.g., a <p> in an alert div)
6 $($btn.attr('data-on-error-write')).text(errorMessage);
7 // Show some elements (e.g., an alert div)
8 $($btn.attr('data-on-error-show')).show();
9 // Hide some elements (e.g., a success/normal div)
10 $($btn.attr('data-on-error-hide')).hide();
11 }).on('ajax:success', function(e) {
12 var $btn = $(e.target);
13 $($btn.attr('data-on-success-show')).show();
14 $($btn.attr('data-on-success-hide')).hide();