【发布时间】:2020-05-03 23:37:38
【问题描述】:
$.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
此脚本用于停止表单提交。 如果返回值为 true,则表单应提交,否则 (false) for 不应提交。
(此代码用于验证表单)
【问题讨论】:
-
您在
stop_billed_reservation_delete.php文件中获得了rid值? -
在异步调用成功函数中返回值没有意义
-
ajax response should be true or false so return value should be true or false是的,成功回调返回 true 或 false(请参阅我之前的评论以实现此返回值的无用性)......但$.ajax立即返回一些 jQuery 对象,而不是当结果已知 -
This script is used for stop to form submission. if return value is true, form should submit, otherwise (false) for should be not submit.最终,您不能通过使用异步函数来阻止表单提交 - preventDefault 不能在以后任意调用 - 您需要重新考虑您的代码(始终防止表单提交,如果这个ajax的结果为真,自己执行表单提交......使用$.ajax -
我知道...但它需要-...就像您接受的答案一样
标签: javascript php jquery ajax asynchronous