Home >Web Front-end >JS Tutorial >jquery multi-asynchronous management usage records
$.when() passes multiple deferred
var ajaxBatch=[]; //构建deferred数组 ... $.when.apply($,ajaxBatch).done();
done() The argument structure in the callback is inconsistent
There will be three situations:
No parameters
$.when()一个deferred参数: [data, textStatus , jqXHR] #假定 x代表[data,textStatus,jqXHR]结构 $.when()多个deferred参数: [x1,x2,x3]
Are you drunk? How to handle it uniformly? ?
Currently using the structure to determine the innermost data
.done(function(){ var params=[].slice.call(arguments); if(typeof params[0][0] !='object'){ //第二种情况返回undefined params=[]; params[0]=[].slice.call(arguments); } //然后遍历结果吧 });