filterrific icon indicating copy to clipboard operation
filterrific copied to clipboard

AJAX does not work with jQuery 3

Open afuno opened this issue 7 years ago • 6 comments

Rails 5.1.3

Gemfile: gem 'jquery-rails' Without turbolinks

application.coffee:

#= require rails-ujs

#= require jquery3
#= require popper
#= require bootstrap

AJAX does not work. If I replace with this line:

#= require jquery

That AJAX starts working.

Why is this happening?

afuno avatar Aug 16 '17 14:08 afuno

Second this. Including 2.2.4 jQuery library seems to bring it back up after 3.2.1 fails.

vzelenko avatar Sep 08 '17 20:09 vzelenko

I am also having this issue after upgrading to jQuery 3. This should be fixed as there are security issues with previous versions of JQuery. Anyone want to help me identify the issue and get this fixed?

enderwiggens avatar Oct 02 '20 18:10 enderwiggens

I also had this problem after upgrading to jQuery 3(no turbolinks installed also).

I just replace

jQuery(document).on('ready page:load', function() {
  Filterrific.init();
});

with

jQuery(document).ready(function() {
  Filterrific.init();
});

in this file https://github.com/jhund/filterrific/blob/master/app/assets/javascripts/filterrific/filterrific-jquery.js

And it works.

I hope it will help someone

mateo9 avatar Nov 18 '20 12:11 mateo9

Any new responde for this issue?

aweiand avatar Jun 24 '21 16:06 aweiand

I also had this problem after upgrading to jQuery 3(no turbolinks installed also).

I just replace

jQuery(document).on('ready page:load', function() {
  Filterrific.init();
});

with

jQuery(document).ready(function() {
  Filterrific.init();
});

in this file https://github.com/jhund/filterrific/blob/master/app/assets/javascripts/filterrific/filterrific-jquery.js

And it works.

I hope it will help someone

Thank you :), works for me with rails 6 and no turbolinks

pramod-wick avatar Jun 29 '21 07:06 pramod-wick

I'm have the same issue, in combine with will_paginate. To fix this, I found this code on Web, wich fix too

module WillPaginateHelper
    class WillPaginateJSLinkRenderer < WillPaginate::ActionView::LinkRenderer
      def prepare(collection, options, template)
        options[:params] ||= {}
        options[:params]['_'] = nil
        super(collection, options, template)
      end
  
      protected
      def link(text, target, attributes = {})
        if target.is_a? Fixnum
          attributes[:rel] = rel_value(target)
          target = url(target)
        end
  
        @template.link_to(target, attributes.merge(remote: true)) do
          text.to_s.html_safe
        end
      end
    end
  
    def js_will_paginate(collection, options = {})
      will_paginate(collection, options.merge(:renderer => WillPaginateHelper::WillPaginateJSLinkRenderer))
    end
  end

Then, use js_will_paginate instead will_paginate (in Rails 5.2.2)

aweiand avatar Jun 29 '21 13:06 aweiand