如何呼叫警报所有Ajax请求完成后?

编程入门 行业动态 更新时间:2024-10-18 01:29:36
本文介绍了如何呼叫警报所有Ajax请求完成后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我做在codeA与jQuery几个请求和 GET 。它看起来像:

I'm making in code a few requests with JQuery and get. It looks like:

$.get('address1', function() { ... }); $.get('address2', function() { ... }); $.get('address3', function() { ... }); // This code should be runned when all 3 requests are finished alert('Finished');

那么,有什么方法来检测是否还有处理请求并运行,只有当所有3请求完成后打上code。

So, are there any ways to detect whether there is still processing request and run marked code only when all 3 requests are finished.

感谢。

推荐答案

您可以使用的延期对象的 [文档] jQuery的1.5介绍:

You can make use of deferred objects [docs] introduced in jQuery 1.5:

$.when( $.get('address1', function() { ... }), $.get('address2', function() { ... }), $.get('address3', function() { ... }) ).then(function() { alert('Finished'); });

参考: jQuery.when

jQuery的学习中心有一个很好的介绍推迟对象/ 的承诺

The jQuery learning center has a nice introduction to deferred objects / promises.

更多推荐

如何呼叫警报所有Ajax请求完成后?

本文发布于:2023-11-14 09:48:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586886.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   完成后   Ajax

发布评论

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

>www.elefans.com

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