基本上我想展示一个加载动画...
这是我正在使用的代码:
$("#mail-change input[type=submit]").click(function(event){
$.post('user_settings.php', $("#mail-change").serialize(), function(res) {
$(res).insertBefore(".grey");
}, 'html')
});
$("#loading").ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
编辑:
$("#mail-change input[type=submit]").click(function(event){
$("#loading").show()
$.post('user_settings.php', $("#mail-change").serialize(), function(res) {
$(res).insertBefore(".grey");
$("#loading").hide();
}, 'html');
});
或:$.ajax({
url : 'user_settings.php',
data: $("#mail-change").serialize(),
beforeSend: function(){
$("#loading").show();
},
complete: function(){
$("#loading").hide();
},
success: function(res) {
$(res).insertBefore(".grey");
}
});
请参考以下链接:
$.post
之前显示加载指示器,并在成功回调中再次隐藏它。请参见我的编辑。 - karim79$.ajax
的beforeSend
和complete
回调函数。我刚刚又编辑了一次。 - karim79