jQuery 检查 JavaScript 是否正在处理
我有许多 jquery 方法调用不同的脚本服务,然后将数据呈现为 html。如何显示“正在处理..”指示器,确定性地表明幕后正在发生某些事情?
我曾考虑过在 getJSOn 调用期间显示和隐藏指示器,但似乎有很多不同的调用。是否有更简单的方法或最佳实践可以实现相同的目标。
I have many jquery methods invokiing different script services and then rendering the data as html. How do I display a "processing .." indicator that deterministically says that something is happening behind the curtains?
I have thought about dislpaying and hiding an indicator during getJSOn calls, but there seems to be so many different calls. Is there an easier way or a best-practice to follow to achieve the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用相同的金刚砂,但还引入一个计数器,该计数器随着每次方法调用而递增,并由回调函数递减。这样,当您将其递减并变为 0 时,您就知道可以再次隐藏处理指示器。
这可能看起来像这样,您显然需要更改函数名称等。
I would suggest the same adamantium, but also introduce a counter that is incremented with each method invocation and decremented by the callback function. That way when you decrement it and it becomes 0 you know you can hide the processing indicator again.
This could look something like this, you'll obviously need to change function names etc.
调用方法时显示状态指示器。隐藏在getJSON的回调函数中。
Show the status indicator when the method is invoked. Hide it in the callback function of getJSON.
如果您不想等待“已加载”状态,这是我的解决方案: http://yannesposito.com/Scratch/multi/blog/2009-10-How-to-preload-your-site-with-style/
Here is my solution if you don't want to wait the 'loaded' state : http://yannesposito.com/Scratch/multi/blog/2009-10-How-to-preload-your-site-with-style/