$.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此腳本用于停止表單提交。如果返回值為真,表單應該提交,否則(假)不應該提交。(此代碼用于驗證表單)
1 回答

qq_花開花謝_0
TA貢獻1835條經驗 獲得超7個贊
默認情況下,Ajax 是異步的,因此它不等待 ajax 響應。async: false不會工作,因為它已經被棄用了??梢栽赼jax函數的success函數中運行表單提交。
$.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.
. . . . . .
}
- 1 回答
- 0 關注
- 98 瀏覽
添加回答
舉報
0/150
提交
取消