3

I have a link with remote: true attribute. It goes to the function then the js.erb file. My question is how can I add loading icon rails way?

For instance, if I put ajax request it is easy;

     $.ajax({
        type: 'POST',
        url: form.attr('action'),
        data: form.serialize(),
        dataType: 'json',
        beforeSend: function() {//add icon here}
        success: function(data){
        },
        error: function() {
        }
      });

But when I work with remote: true with link or button where should I put the loading icon.

PS: I do not want to add smth like below to the dom.

$('#mybutton').on('click', function(){$('#div-to-loading').prepend('.loading-icon')})

EDIT

Please read my question carefully. I know how to add loading icon with ajax call. I am asking how to do it with rails way. I have a link with remore:true option. It goes to controller action then rendering js file myfunc.js.erb.

Where should I put loading icon?

Shalafister's
  • 761
  • 1
  • 7
  • 34
  • Possible duplicate of [How to use ajaxStart to show loading spinner?](http://stackoverflow.com/questions/31199304/how-to-use-ajaxstart-to-show-loading-spinner) http://stackoverflow.com/questions/1191485/how-to-call-ajaxstart-on-specific-ajax-calls – Gokul Mar 18 '17 at 11:08
  • Did you ever figure this out? – DelPiero Feb 12 '20 at 17:59

0 Answers0