admin管理员组文章数量:1415460
Is it possible to specify time after which I can show busy indicator?
My code for busy indicator is quite simple:
jQuery.ajaxSetup( {
beforeSend:function ()
{
jQuery( "#busy-indicator" ).show();
}, plete:function ()
{
jQuery( "#busy-indicator" ).hide();
}
} );
But often Ajax request is faster then appearing indicator, therefore I'd like to show it for request which take lets say at least 1 second, is it possible? Or Do you have idea how to do it?
Is it possible to specify time after which I can show busy indicator?
My code for busy indicator is quite simple:
jQuery.ajaxSetup( {
beforeSend:function ()
{
jQuery( "#busy-indicator" ).show();
}, plete:function ()
{
jQuery( "#busy-indicator" ).hide();
}
} );
But often Ajax request is faster then appearing indicator, therefore I'd like to show it for request which take lets say at least 1 second, is it possible? Or Do you have idea how to do it?
Share Improve this question asked Jul 23, 2012 at 9:55 kamilkamil 3,5221 gold badge43 silver badges64 bronze badges 1- 2 in the beforeSend callback launch a timeout that will show your loader after a while and in the plete callback cancel the timeout and hide the loader. – yent Commented Jul 23, 2012 at 9:57
2 Answers
Reset to default 7This does the trick:
var timeout;
jQuery.ajaxSetup( {
beforeSend:function ()
{
if (timeout) { clearTimeout(timeout); }
timeout = setTimeout(function() {
jQuery( "#busy-indicator" ).show();
}, 1000);
},
plete:function ()
{
if (timeout) { clearTimeout(timeout); }
jQuery( "#busy-indicator" ).hide();
}
});
jQuery.ajaxSetup( {
beforeSend:function ()
{
$( "#busy-indicator" ).stop(1,0).hide().delay(1000).show();
},
plete:function ()
{
$( "#busy-indicator" ).stop(1,0).hide();
}
});
Doesn't this also work?
本文标签: javascriptajax quotbusyquot indicator but only for longer requestsStack Overflow
版权声明:本文标题:javascript - ajax "busy" indicator but only for longer requests - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745173004a2646087.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论