jQuery的阿贾克斯装载机 [英] jquery ajax loader
本文介绍了jQuery的阿贾克斯装载机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的脚本:
$("#addk").bind("click", function(event){
//alert("here!");
$("#loader-overlay").show();
$.ajax({
'async':"False",
'type': "POST",
'url': "http://url/feedback/",
'data': $("#form").serialize(),
'success': function(msg){
$("#errors").html(msg);
},
'error' : function(){
$("#errors").html('<p>fail</p>');
}
});
$("#loader-overlay").hide();
//return false;
});
由于某些原因,装载机屏幕永远不会出现,即使AJAX运行几秒钟。如果我写
For some reason the loader screen never appears, even though the ajax runs for a few seconds. If i write
$("#loader-overlay").show();
进入控制台,然后它工作得很好。
into console, then it works just fine.
它可能很简单的东西,我只是不能把我的手指上。
Its probably something very simple that i just cant put my finger on.
阿伦
推荐答案
您也许应该有显示和隐藏装载作为Ajax请求中回调。退房:<一href="http://api.jquery.com/jQuery.ajax/#callback-functions">http://api.jquery.com/jQuery.ajax/#callback-functions
You should probably have the showing and hiding of the loading as callbacks within the ajax request. Check out: http://api.jquery.com/jQuery.ajax/#callback-functions
所以,你可以做:
$.ajax({..., beforeSend: function(){ /* show the loading thing */ },
complete: function(){ /* hide the loader */ }});
这篇关于jQuery的阿贾克斯装载机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文