等到jquery ajax请求列表完成?

编程入门 行业动态 更新时间:2024-10-25 07:31:41
本文介绍了等到jquery ajax请求列表完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

与此问题几乎相同:请等待直到所有jQuery Ajax请求完成了吗?

但是我的问题很糟糕:

我正在处理许多ajax请求,并将它们保存在一个数组中:

That I'm doing many ajax requests, and I save them in an array:

var events = []; for(var i = 0; i < 10; ++i) { events.push($.ajax({...})); } $.when(events).done(function() { // do something when all requests are done. });

正如相关问题所表明的那样,$ .when方法按顺序按一些jqXHR对象,但是在这里我要其中的一个列表.

As the related question tells, the $.when method takes some jqXHR object in order, but here I want a list of them taken.

我阅读了 api.jquery中的文档. com/jQuery.when/#jQuery-when-deferreds ,但该方法似乎不支持这种情况(将jqXHR的列表传递给$.when函数)

And I read the documents in api.jquery/jQuery.when/#jQuery-when-deferreds, but the method seemed not supporting this case (passing a list of jqXHR to $.when function)

怎么可能?请帮助.

推荐答案

,您需要将Promise作为参数列表(如$.when(promise1, promise2, promise3))传递给 $.when(),而不是数组,因此请使用 Function.apply().

you need pass the promises as an argument list(like $.when(promise1, promise2, promise3)) to $.when(), not as an array so use Function.apply().

$.when.apply($, events).then(function() { // do something when all requests are done. });

更多推荐

等到jquery ajax请求列表完成?

本文发布于:2023-11-26 16:49:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:列表   jquery   ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!