mac不知道为何,文章字数一多,浏览器就重启。只好分开写了。

In the event a Deferred was resolved with no value, the corresponding doneCallback argument will be undefined. If a Deferred resolved to a single value, the corresponding argument will hold that value. In the case where a Deferred resolved to multiple values, the corresponding argument will be an array of those values. For example:

var d1 = $.Deferred();
var d2 = $.Deferred();
var d3 = $.Deferred();
$.when( d1, d2, d3 ).done(function ( v1, v2, v3 ) {
console.log( v1 ); // v1 is undefined
console.log( v2 ); // v2 is "abc"
console.log( v3 ); // v3 is an array [ 1, 2, 3, 4, 5 ]
});
d1.resolve();
d2.resolve( "abc" );
d3.resolve( 1, 2, 3, 4, 5 );
在一个事件中,deferred无完成值,对应的done参数将为undefined。如果一个deferred完成后仅一个值,读经的参数将获取到那个值。这样,deferred完成值为复合值,那对应的参数将是一个数组。例子如下:见上。
 
In the multiple-Deferreds case where one of the Deferreds is rejected, jQuery.when() immediately fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be unresolved at that point. The arguments passed to the failCallbacks match the signature of the failCallback for the Deferred that was rejected. If you need to perform additional processing for this case, such as canceling any unfinished Ajax requests, you can keep references to the underlying jqXHR objects in a closure and inspect/cancel them in the failCallback.
在复合deferreds中,其中一个失败了,jQuery.when()立即启动fail回调作为其主deferred。注意,在那个点有些deferreds或许仍旧处于未完成状态。传递给fail回调的参数会为失败的deferred匹配到fail回调的标记。这种情况下如果你需要执行额外的进程,诸如取消未完成的ajax请求,可以使用闭包保持对这个jqXHR对象的引用,并在fail回调中对其取消或检验。
 

Examples:

Execute a function after two Ajax requests are successful. (See the jQuery.ajax() documentation for a complete description of success and error cases for an ajax request).

$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) ).done(function( a1, a2 ) {
// a1 and a2 are arguments resolved for the page1 and page2 ajax requests, respectively.
// Each argument is an array with the following structure: [ data, statusText, jqXHR ]
var data = a1[ 0 ] + a2[ 0 ]; // a1[ 0 ] = "Whip", a2[ 0 ] = " It"
if ( /Whip It/.test( data ) ) {
alert( "We got what we came for!" );
}
});
在两个ajax请求成功后执行一个函数。(查看jQuery.ajax()文档获取完整的关于成功和错误状态的ajax请求的文档。)
 
Execute the function myFunc when both ajax requests are successful, or myFailure if either one has an error.
$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) )
.then( myFunc, myFailure );
当两个ajax请求成功后,执行函数myFunc,或者在二者之一出错后执行myFailure.

随机推荐

  1. Spring Autowired原理

    今天来整理一下Spring的自动装配 autowire一节,在这里我们要解决以下问题: 什么是自动装配? 自动装配的意义? 自动装配有几种类型? 如何启用自动装配? 自动装配将引发的问题? 一.什么是 ...

  2. inline函数的总结

    在函数返回类型前加上关键字inline就可以将函数指定为内联函数: inline const string& shortString(const string &s1, const s ...

  3. Monkey自动化测试

    Monkey简介 语法参数 实际应用 一.Monkey简介 1.什么是Monkey? 基于健壮性.稳定性的考虑:如果将一个应用交给一个人长时间不停地乱点乱按,程序会怎么样? 有时候运行相同系列的测试, ...

  4. 【三】shiro入门 之 Realm

    Realm:域,Shiro 从从Realm获取安全数据(如用户.角色.权限),就是说SecurityManager要验证用户身份,那么它需要从Realm获取相应的用户进行比较以确定用户身份是否合法:也 ...

  5. Mining Your Own Business UVALive - 5135(点双联通分量)

    these days I‘m tired!,but very happy... #include<cstdio> #include<cstring> #include<s ...

  6. 【CodeChef-SPCLN】Cleaning the Space

    https://odzkskevi.qnssl.com/7dfb262544887eff6fb35bfb444759d6?v=1502084197 做法是类似于最大割之类的东西,把每个碎片按照按钮拆点 ...

  7. [NOI2011]兔兔与蛋蛋游戏 二分图博弈

    题面 题面 题解 通过观察,我们可以发现如下性质: 可以看做是2个人在不断移动空格,只是2个人能移动的边不同 一个位置不会被重复经过 : 根据题目要求,因为是按黑白轮流走,所以不可能重复经过一个点,不 ...

  8. redis2.8.xx安装配置

    一.简介    Redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有序集 ...

  9. linux 递归删除目录文件

    比如删.svn文件 >find . -name ".svn" | xargs -exec rm -rf

  10. mysql权限管理,用户管理

    1 创建用户 mysql> truncate table user; //先删除所有用户 mysql> CREATE USER  'paris'@'localhost' IDENTIFIE ...