Ajax在Rails 4中加载微调器

我在rails中发送ajax请求,我收到了一些数据表的数据

使用remote:true在链接标记上发生ajax触发

这是index.js.erb(对此进行了ajax调用)

$('.lessons_table').removeClass('hidden'); $('.lessons').empty();  $('.lessons').append(''); $('.lessons').append(''); $('.lessons').append(''); $('.lessons').append(''); $('.lessons').append(''); $('.lessons').append(''); $('.lessons').append(''); $('.lessons').append('');  

的application.js

 $(document).ready(function () { // hide spinner $(".spinner").hide(); $(document).ajaxStart(function() { $(".spinner").show(); }).ajaxComplete(function() { var $loading = $(".spinner"); setTimeout(function(){ $loading.hide(); },1000); //Timeout so you can see the loading happen }); }); 

index.html.erb

 
Loading

我想要的是,当我点击链接来检索这些数据时,我希望在指定的时间段内出现加载文本或css微调器,当该微调器或文本消失时,数据就会出现。

我在application.js中使用了代码,但它无法正常工作。

为了将来参考,这实际上对我有用,不需要定时器等。 只要ajax请求没有完成就需要它。

 $(".spinner").hide(); $(document).ajaxStart(function() { $(".spinner").fadeIn('slow'); }).ajaxStop(function() { $(".spinner").hide(); });