JQuery ajax: before event

I saw some colleagues use this on rails

    $('[data-once=true]').live('ajax:before', function(request, e) {

});

However, I am trying to use it with jquery and it does not work, does this event come with a rails jquery adapter?

+3
source share
3 answers

Yes, ajax:beforea jQuery event that adds / rails triggers, although this is not the latest version ajax:beforeSend. In jQuery, though ( ajax:beforewas around before the JS agnostic changes were tied to rails), you can just connect to it globally using a ajaxSendglobal event , like this:

$(document).bind('ajaxSend', function(e, request, options) {
  $('[data-once=true]').something();
});
+4
source

dev, , , AJAX ole 'JS:

$.ajax({
   beforeSend: function(){

     alert("Before");

   },
   complete: function(){

    alert("after");

   }
 });

, AJAX . AJAX.

. jQuery AJAX Events Documentation.

+2

This is 'ajax:before'not a useful event to .live()handle if you have not defined a custom event with this name.

+1
source

Source: https://habr.com/ru/post/1782972/


All Articles