由网友(再见不如不见)分享简介:我想实现的解决方案,如本post但不能让它的工作。I am trying to implement the solution as outlined in this post but can't get it to work.application.js$(document).ready(function(){$....
我想实现的解决方案,如本post但不能让它的工作。
I am trying to implement the solution as outlined in this post but can't get it to work.
application.js
$(document).ready(function(){
$.ajaxSetup({
beforeSend:function(){
$('#loading').show();
},
complete:function(){
$('#loading').hide();
}
});
});
application.html.erb
<div id="loading" style="display:none;"><img src="/img/ajax-loader-circle.gif" ></br></br>Please wait...</div>
这是我的形式,我加了:远程=&GT;真正的
,我可以告诉大家,一个AJAX调用有人在看Rails的日志。然而, beforeSend秀
从未被触发。思考?
From my form, I added :remote => true
and I could tell that an AJAX call was made looking at Rails logs. However, beforeSend show
never got triggered. Thoughts?
推荐答案
我会建议使用:
$('#loading').ajaxStart(function(){
$(this).show();
}).ajaxStop(function(){
$(this).hide();
});
如果你想为一个特定的形式ID:
or if you want it for a particular form ID:
$('#someFormID')
.ajaxStart(function() {
$('#loading').show();
})
.ajaxStop(function() {
$('#loading').hide();
});
请确保它包裹在一个DOM就绪块(像你这样做)。这些都是从我的应用程序之一两种工作的例子。
Make sure it's wrapped in a DOM ready block (like you've done). These are both working examples from one of my apps.
相关推荐
最新文章