Skip to content

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

Open
@zulkufdemirhan

Description

@zulkufdemirhan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions