惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
P
Privacy International News Feed
T
Tenable Blog
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
S
Securelist
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
月光博客
月光博客
T
The Blog of Author Tim Ferriss
Scott Helme
Scott Helme
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
C
Cisco Blogs
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
Security Latest
Security Latest
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
I
InfoQ
Spread Privacy
Spread Privacy
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
A
About on SuperTechFans
博客园_首页
Engineering at Meta
Engineering at Meta
Project Zero
Project Zero
Latest news
Latest news

博客园 - 猫狼

安卓连接usb camera 安卓手机连接USB摄像头代码 安装Memurai 把“休眠”功能找回来,并设置成一合上盖子就生效 mathtype安装后在office无法启动,提示运行时错误53, 文件未找到:MathPage.WLL ASP.NET Web Site Project 中集成 Hangfire 并实现图片/视频压缩后台任务 SQL SERVER 数据库压缩日志步骤 Latex的一个错误, SQL 学习笔记 升级 ASP.NET 网站项目到 C# 6.0 或更高版本 C#程序集合并工具-ILRepack manim 安装 manim一个坑爸爸的问题 manim安装纪实 去掉快捷方式的小箭头 VS2022转到定义功能异常解决方案 url 传递加号,asp.net解析参数的正确处理参数 获取自然周数的下拉列表 移出Json对象的三级属性 梦记:又要去交流? 一段VBA的代码,到处是坑 C# 返回文件夹及子目录 解决JS跨域访问的问题 利用Jquery的map函数将json数据行转化为表格 模访京东商城jQuery省市区三级联动选择(横向DIV)
多个AJAX请求,带执行进度及结果
猫狼 · 2024-07-20 · via 博客园 - 猫狼
    function CreateAll() {
        var len = $("[src='/images/err.png'][title='点击重新生成']").length;
        var layerMsg = layer.open({
            title: "正在生成,共有" + len + "个试题正在生成",
            content: "当前第已成功生成<span id='buildOk' style='color:red; padding:5px;'>0</span>个!",
            btn: ['关闭'],
            yes: function() {
                layer.close(layerMsg);
            },
            success: function() {
                var cnt = 0;
                var ok = 0;
                var ids = new Array;
                $("[src='/images/err.png'][title='点击重新生成']").each(function() {
                    ids.push($(this).attr("id").replace("ibtn", ""));
                });
                $("#curItem").text(ids.length);
                var requests = new Array;
                for (var i = 0; i < ids.length; i++) {
                    var id = ids[i];
                    var aid = $("#ibtn" + id).data("aid");
                    var orderNo = $("#ibtn" + id).data("orderno");
                    requests.push(createItem(aid, id, orderNo, $("#ibtn" + id), false));
                }
               
                // 初始化进度为0
                var progress = 0;

                // 使用$.when()执行顺序
                $.when.apply($, requests).then(
                    function () {
                        // 所有请求成功完成时的回调
                        layer.close(layerMsg);
                    },
                    function () {
                        // 任何一个请求失败时的回调
                        alertify.error("发生了一个错误的请求!");
                    }
                );

                // 对每个请求进行进度更新
                requests.forEach(function (request, index) {
                    request.progress(function (e) {
                        // 更新进度条
                        progress = (index + e.loaded / e.total) / requests.length;
                        console.log('Progress:', progress);
                    }).done(function (response) {
                        ok++;
                        // 单个请求成功时的回调
                        console.log('Request ' + index + ' completed:', response);
                        $("#buildOk").text(ok);
                    }).fail(function (error) {
                        // 单个请求失败时的回调
                        //console.log('Request ' + index + ' failed:', error);
                    });
                });
            }
        });

    }

这里用到了第三方的两个组件,一个是layer,一个alertify,异步函数是

createItem(aid, id, orderNo, $("#ibtn" + id), false)

在这个函数体内要ajax请求,要加上done的回调 ,格式是$.ajax({请求内容}).done(function(){'回调内容'}),要不然progress会报错.