2015-07-21 76 views
-1

我需要检测我的浏览器处于等待状态或繁忙状态使用Jquery并实现一个加载程序也。我已经使用的代码如下如何检测我的浏览器繁忙或等待状态使用jquery

<script type="text/javascript" src="/assets/script/jquery-1.4.2.min.js"></script> 
<script type="text/javascript"> 
$(function() { 
    $.ajax({ 
     type: "GET", 
     url: "sync_bills.php", 
     success: function(resp) { 
      $("#results").html(resp); 
     } 
    }); 
}); 
</script> 

<div id="results"><img src="images/loading.gif" width="16" height="16" alt="Loading..." /></div> 
+0

ahm你会发现什么?可能是异步和同步机制可能是你的查询提示 – donald123

+0

提供的代码有什么问题?预期的行为是什么?请你能详细阐述一下吗? – fcalderan

回答

1

有jQuery的阿贾克斯beforeSend两件事情和complete

作出这样

$(function() { 
$.ajax({ 
    type: "GET", 
    url: "sync_bills.php", 
    beforeSend : function(){ 
     $("#loader").show(); 
    }, 
    success: function(resp) { 
     $("#results").html(resp); 
    }, 
    complete: function(resp) { 
     $("#loader").hide(); 
    }, 
    }); 
}); 

这对我的作品改变你的代码,如果我需要装载

+0

在OP代码中,'success'回调已经覆盖了加载器映像,所以不需要隐藏加载器完成(可能在'error') – fcalderan

+0

是的..但是如果它的成功没有执行,那么也完成将工作 –