我如何使用jquery ajaxstart和ajaxstop与$ .post?
基本上我想显示一个加载GIF …
这是我正在使用的代码:
$("#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"); } });
看到: