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

蹲街弑〆低调 提交于 2019-12-31 01:26:30

问题


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:


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"



来源:https://stackoverflow.com/questions/12478565/using-an-equivalent-of-when-done-in-jquery-1-4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!