jquery-ujs icon indicating copy to clipboard operation
jquery-ujs copied to clipboard

Ajax responses not working on js.erb requests in Rails

Open zulkufdemirhan opened this issue 2 years ago • 0 comments

Hi folks,

I want to track "Ajax" requests in application.js as globally in my Ruby on Rails project but even though I used all the possibilities offered by jQuery and ujs ( ajax:complete, ajax:success, ajax:error, ajaxComplete() and ajaxSuccess ), I could not run it.

I observed that this problem usually occurs after js.erb response/requests.

application.js:

$(function() {
  $('document').on('ajax:complete', function() {
    alert('ajax:complete event triggered');
  });

  $('document').on('ajax:success', function() {
    alert('ajax:success event triggered');
  });
});

Ruby 2.7.8 Rails 6.0.3 jQuery: 3.5.1 Rails/ujs: 7.0.4

PS: I solved this problem using "Vanilla JS" by handling the "XMLHttpRequest" property.

zulkufdemirhan avatar Jan 25 '24 08:01 zulkufdemirhan