gpt4 book ai didi

javascript - 显示长复选框单击事件的进度

转载 作者:行者123 更新时间:2023-12-02 19:08:07 24 4
gpt4 key购买 nike

我有一个复选框,选中它会触发对服务器的长时间调用。我想在用户等待调用时显示旋转的 while .gif 图像,但该图像未显示。下面是我的代码片段:

$('#chk').click(function () {
$('span.progress-indicator').show(); //the gif image

$.ajaxSetup({ asynch: false});

LongServerCallMethod();

$('span.progress-indicator').hide(); //the gif image
});

最佳答案

将长方法调用放在 setTimeout 中,以便浏览器有时间首先渲染 gif。但是,您会注意到,由于浏览器被异步调用锁定,因此旋转器不会旋转。解决这个问题的唯一方法是不使用 async: false

setTimeout(function(){
LongServerCallMethod();

$('span.progress-indicator').hide(); //the gif image
},0);

如果您有时间,您确实应该重写代码以不使用 async: false 因为时间是唯一可能阻止您转换 async: false 代码为 async: true

关于javascript - 显示长复选框单击事件的进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14129257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com