Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax responses not working on js.erb requests in Rails #524

Open
zulkufdemirhan opened this issue Jan 25, 2024 · 0 comments
Open

Ajax responses not working on js.erb requests in Rails #524

zulkufdemirhan opened this issue Jan 25, 2024 · 0 comments

Comments

@zulkufdemirhan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant