如何使用jquery ajaxstart和ajaxstop与$.post?

前端之家收集整理的这篇文章主要介绍了如何使用jquery ajaxstart和ajaxstop与$.post?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
基本上我想显示一个加载gif …

这里是我使用的代码

  1. $("#mail-change input[type=submit]").click(function(event){
  2.  
  3. $.post('user_settings.PHP',$("#mail-change").serialize(),function(res) {
  4.  
  5. $(res).insertBefore(".grey");
  6.  
  7. },'html')
  8.  
  9. });

解决方法

  1. $("#loading").ajaxStart(function() {
  2. $(this).show();
  3. }).ajaxStop(function() {
  4. $(this).hide();
  5. });

编辑:

  1. $("#mail-change input[type=submit]").click(function(event){
  2. $("#loading").show()
  3. $.post('user_settings.PHP',function(res) {
  4. $(res).insertBefore(".grey");
  5. $("#loading").hide();
  6. },'html');
  7. });

要么:

  1. $.ajax({
  2. url : 'user_settings.PHP',data: $("#mail-change").serialize(),beforeSend: function(){
  3. $("#loading").show();
  4. },complete: function(){
  5. $("#loading").hide();
  6. },success: function(res) {
  7. $(res).insertBefore(".grey");
  8. }
  9. });

看到:

> http://api.jquery.com/ajaxStart/
> http://api.jquery.com/ajaxStop/
> http://docs.jquery.com/Ajax_Events
> http://api.jquery.com/category/ajax/global-ajax-event-handlers/

猜你在找的jQuery相关文章