ajax 的 promise

$.when().done().fail()

$.when($.ajax("test1.html"),$.ajax("test2.html")).done(function(){console.log(“两个ajax都成功了”)}).fail(function(){console.log("一个或全都都失败了")})

这段代码的意思是,先执行两个操作$.ajax("test1.html")和$.ajax("test2.html"),如果都成功了,就运行done()指定的回调函数;如果有一个失败或都失败了,就执行fail()指定的回调函数。

posted @ 2018-04-23 10:43  慕东  阅读(133)  评论(0编辑  收藏  举报