在jQuery 1.4中使用等价的$ .when().done() [英] Using an equivalent of $.when().done() in jQuery 1.4

查看:113
本文介绍了在jQuery 1.4中使用等价的$ .when().done()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行两个不同的JSON请求,并将这些请求合并到一个函数中.我希望使用以下构造:

I need to do two different JSON requests and combine those requests in one function. I would have liked to use the following construction:

$.when(
       $.getJSON(url1),
       $.getJSON(url2)
).done(function(data1, data2) {
       someFunction(data1, data2);
});

不幸的是,对于此项目,我们使用的是jQuery 1.4和$ .when(从jQuery 1.5开始引入). jQuery 1.4中有与此等效的东西吗?

Unfortunately, for this project we are using jQuery 1.4 and $.when was introduced since jQuery 1.5. Is there some equivalent for this in jQuery 1.4?

提前谢谢!

推荐答案

为实现此功能,我完成了一个数组,其中每个元素都是一个标志,用于指示特定的getJSON是否已完成.同样在每个成功函数上,我检查要完成的完整数组,如果没有(确实如此),我将获得的json(和某些上下文)添加到其他结果数组"中.但是,如果一切都完成了,那么我将对结果数组"执行最后的功能

To implement this functionality, I have done an array where each element is a flag that says if that particular getJSON has finished. Also on each success function I check the full array to be completed, if not (well realy allways) I add the obtained json (and some context) to other "array of results". But if all are done, then I execute the final funcion against the "array of results"

这篇关于在jQuery 1.4中使用等价的$ .when().done()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆