我很确定这不应该那么难。我有一个在提交时运行以下函数的表单:
function FORMVALIDATE_add_rota_entry() {
var rota_date = $("#rota_date").val();
var rota_id = $("#rota_id").val();
var am_pm = $("#am_pm").val();
if(rota_date == "")
{
alert("Please enter a date.");
return false;
}
if(rota_id == "error")
{
alert("Please select a rota from the list.");
return false;
}
// check if that rota has already been entered for that date and am/pm
$.ajax({
async:false,
type:"POST",
url:"/modules/rotas/check_rota_entry_existence",
data:{rota_date:rota_date, rota_id:rota_id, am_pm:am_pm},
success: function(result) {
if(result != "0")
{
alert("This rota has already been added to this date, "+am_pm+".");
return false;
}
}
});
}
它在表单标签中通过以下方式调用:
onsubmit="return FORMVALIDATE_add_rota_entry();"
它在前两个 rota_date 和 rota_id 上运行良好,当它们应该出现警报时,它会阻止表单提交,但是当它到达 ajax 调用时,它会很好,返回正确的结果,当它发出警报时应该,但返回 false 似乎并没有阻止表单提交。有没有人有任何想法,因为我很难过!
谢谢!