本文介绍了如何呼叫警报所有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请求完成后?
发布评论