Home >Web Front-end >JS Tutorial >jquery multi-asynchronous management usage records

jquery multi-asynchronous management usage records

伊谢尔伦
伊谢尔伦Original
2016-11-21 13:15:181024browse

  $.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);
}
//然后遍历结果吧
});



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Why use WebpackNext article:Why use Webpack