Using an equivalent of $.when().done() in jQuery 1

2019-02-24 22:53发布

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);
});

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?

Thanks in advance!

1条回答
Fickle 薄情
2楼-- · 2019-02-24 23:51

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"

查看更多
登录 后发表回答