var display_message="";
$('input:checked').each(function(index) {
var profile_id=$(this).val();
$.ajax({
type: 'post',
url: 'myUrl',
data: data,
success: function(data) {
if(data=="ok")
display_message = display_message + data +", ";
}
});
});
alert(display_message);
alert(display_message);
if($.trim(display_message)!=""){
jAlert("Your birthdate already exits in "+display_message.substring(0, display_message.length - 2)+".", "Bdate");
return false;
}
在此代码中,我使用两个alert-box来显示display_message变量值。 当我成功运行这个代码,在第一个警告框中我得到空白值和第二个警告框我得到的价值,我需要,然后它会进入如果条件。 如果我不使用警报框,那么它将始终在display_message变量中取空值,并且永远不会进入if条件。所以我需要更改以运行此代码而不使用警报框?如何等待所有Ajax查询完成(并使用组合结果)
亲爱的mrtsherman,我不能使用if条件在每个loop.i使用if条件外循环,因为我在disaplay_message varible中添加数据,如果它不为null,那么它会进入if条件并返回false; – 2011-12-17 07:12:44