$.ajax({
async:false,
url: "ajax/stop_billed_reservation_delete.php",
type: "POST",
dataType : "json",
data : { "rid" : <?php echo $_GET['reservationId']; ?> },
success: function(result){
console.log(result);
return result;
}
});我的目标是返回ajax响应。但是在返回响应脚本运行其他部分之前。我怎样才能解决这个问题!
ajax响应应该是true或false,因此返回值应该是true或false。
此脚本用于停止以形成提交。如果返回值为真,则应提交表单,否则(false)不应提交。
(此代码用于验证表单)
发布于 2020-01-17 04:51:09
Ajax默认是异步的,因此它不等待ajax响应。async: false不能工作,因为它已经被废弃了。您可以在ajax函数的成功函数中运行表单提交。
$.ajax({
url: "ajax/stop_billed_reservation_delete.php",
type: "POST",
dataType : "json",
data : { "rid" : <?php echo $_GET['reservationId']; ?> },
success: function(result){
console.log(result);
if(result){
submitForm(); //Run the function that will submit the form.
}
}
});
function submitForm(){
//Relevant code for submitting the form.
. . . . . .
}https://stackoverflow.com/questions/59781304
复制相似问题