jQuery 检查 JavaScript 是否正在处理

发布于 2024-08-12 09:38:52 字数 151 浏览 1 评论 0原文

我有许多 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉城已无爱 2024-08-19 09:38:52

我建议使用相同的金刚砂,但还引入一个计数器,该计数器随着每次方法调用而递增,并由回调函数递减。这样,当您将其递减并变为 0 时,您就知道可以再次隐藏处理指示器。

这可能看起来像这样,您显然需要更改函数名称等。

var openCalls = 0;

function MethodInvocation() {
    $(".indicator").show();
    openCalls++;
}

function Callback() {
    openCalls--;

    if(openCalls == 0) {
        $(".indicator").hide();
    }
}

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.

var openCalls = 0;

function MethodInvocation() {
    $(".indicator").show();
    openCalls++;
}

function Callback() {
    openCalls--;

    if(openCalls == 0) {
        $(".indicator").hide();
    }
}
英雄似剑 2024-08-19 09:38:52

调用方法时显示状态指示器。隐藏在getJSON的回调函数中。

Show the status indicator when the method is invoked. Hide it in the callback function of getJSON.

盛夏尉蓝 2024-08-19 09:38:52

如果您不想等待“已加载”状态,这是我的解决方案: 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文