如何判断多个ajax请求完成,如何检查多个Ajax请求的完成?

我正在执行多个(3)ajax请求。我怎样才能检查他们是否都成功返回,并且只有在这之后再对输出做些什么。我想过要链接请求,但这样请求不会同时执行。如何检查多个Ajax请求的完成?

最终我试图加载三个表格,并在加载后为他们的位置设置动画。只有在加载完所有表后,动画才会发生。

此外,处理多个ajax调用有什么好的做法?目前,语法只是重复前面的内容时看起来并不“美观”。

谢谢!

这里是我的代码:

// THIS TABLE

$.ajax({

type: 'POST',

url: 'includes/content/bookingsystem/b_dayview.php',

data: $(this).attr('name') + '=true',

success: function(output) {

$('#bookingTableThis').animate({

left: direction + '=820'

}, 500, function() {

$('#bookingTableThis').html(output);

});

}

});

// PREV TABLE

$.ajax({

type: 'POST',

url: 'includes/content/bookingsystem/b_dayview.php',

data: $(this).attr('name') + '=true&dateShift=prev',

success: function(output) {

$('#bookingTablePrev').animate({

left: direction + '=820'

}, 500, function() {

$('#bookingTablePrev').html(output);

});

}

});

// NEXT TABLE

$.ajax({

type: 'POST',

url: 'includes/content/bookingsystem/b_dayview.php',

data: $(this).attr('name') + '=true&dateShift=next',

success: function(output) {

$('#bookingTableNext').animate({

left: direction + '=820'

}, 500, function() {

$('#bookingTableNext').html(output);

});

}

});

Genesis的答案是当场就可惜它产生的另一个问题。很多时候,我在Javascript中传递变量时遇到了问题 - 在这种情况下也是如此。每个AJAX调用的输出不喜欢显示的“则”函数内:

var outputThis;

var outputPrev;

var outputNext;

$.when(function(){

// THIS TABLE

$.ajax({

type: 'POST',

url: 'includes/content/bookingsystem/b_dayview.php',

data: $(this).attr('name') + '=true',

success: function(output) { outputThis = output; }

});

// PREV TABLE

$.ajax({

type: 'POST',

url: 'includes/content/bookingsystem/b_dayview.php',

data: $(this).attr('name') + '=true&dateShift=prev',

success: function(output) { outputPrev = output; }

});

// NEXT TABLE

$.ajax({

type: 'POST',

url: 'includes/content/bookingsystem/b_dayview.php',

data: $(this).attr('name') + '=true&dateShift=next',

success: function(output) { outputNext = output; }

});

}).then(function(){

// THIS

$('#bookingTableThis').animate({

left: direction + '=820'

}, 500, function() {

$('#bookingTableThis').html(outputThis);

});

// PREV

$('#bookingTablePrev').animate({

left: direction + '=820'

}, 500, function() {

$('#bookingTablePrev').html(outputPrev);

});

// NEXT

$('#bookingTableNext').animate({

left: direction + '=820'

}, 500, function() {

$('#bookingTableNext').html(outputNext);

});

});

2011-07-16

Dusty

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值