我有一个页面,其中发生了许多ajax操作.我显示了一个微调器,指示请求正在处理中.
I have a page where a lot of ajax action is taking place. I show a spinner to indicate the request is being processed.
其中一些请求时间很长,其中一些请求很快.当反应很快到来时,那些纺纱厂更是讨厌而不是援助.
Some of those requests long time and some of them are quick. When the response comes quickly then those spinners are more of a nuisance than an aid.
这就是我想要的.自请求提交以来超过50毫秒,仅显示微调框.
This is what I wanted. Display the spinner only if it has been more than 50ms since the request was submitted.
这意味着启动请求时,微调器开始计时.如果响应在50毫秒之前到来,则响应将使微调框隐藏.
It means when the request is initiated spinner starts counting time. If a response comes before 50ms then response will make spinner hide.
但是,如果在50毫秒内未出现响应,则显示微调器.
However if response does not come in 50ms then show spinner.
已经有任何可以帮助我入门的插件了.
Is there any plugin already out there that might help me get started.
谢谢
推荐答案可以使用原始JavaScript轻松完成此操作.无需插件.
This can be easily accomplished using vanilla JavaScript. No need for a plug-in.
要在50毫秒后显示微调器:
To show the spinner after 50ms:
var t = setTimeout("showSpinner()", 50);如果调用在50ms之前成功(在AJAX回调内部),然后取消超时:
And then to cancel the timeout if the call succeeds before 50ms (inside the AJAX callback):
clearTimeout(t);更多推荐
仅在50毫秒后显示微调器
发布评论