我正在使用 onsubmit="return check_for_conflict()" 调用此函数:
function check_for_conflict(){
var client_id = $('#agent_select').val();
//Stop submit if no agent selected.
if (client_id == 0){
alert("Please select an agent.")
return false;
}
var duration = $('#select_job_duration').val();
var id = $('#input_id').val();
var dat = $('#input_date').val();
var st_time = $('#input_st_time').val();
//Check if scheduling conflict and stop submit if there is a conflict.
$.post("check_for_conflicts.php", { job_duration: duration, provider_id: id, job_date: dat, job_st_time: st_time },
function(data){
console.log(data.status);
if(data.status == 'conflict'){
alert("There is a conflict with this time.")
return false;
}
}, "json"
);
//Continue submit if now scheduled conflicts.
return true;
}
我有两个检查来阻止表单提交。第二次检查取决于 .post 响应。这部分不起作用,因为它在 .post 完成之前达到了最终的“返回真”。如何使用 .post 响应来阻止提交表单?