直接上码
<script type="text/javascript">
//第一个ajax
var ajax1 = $.ajax({
url: '/test/t',
dataType: 'json',
type: 'get'
}).done(function() {
alert("1111成功啦!");
}).fail(function() {
alert("1111失败了...");
});
//第二个ajax
var ajax2 = $.ajax({
url: '/test/t',
dataType: 'json',
type: 'get',
}).done(function() {
alert("222成功啦!");
}).fail(function() {
alert("2222失败了...");
});
//when函数,在第一个ajax、第二个ajax都执行完毕后,才执行done函数
$.when(ajax1,ajax2).done(function(d1,d2){
alert(JSON.stringify(d1[0]) +"--"+JSON.stringify(d2[0]));
}).fail(function(){
alert('error');
});
解释参看以下链接,非常感谢:
https://www.cnblogs.com/jarson-7426/p/5511734.html
http://blog.csdn.net/painerch/article/details/47450349