【发布时间】:2018-05-02 19:24:01
【问题描述】:
我有一个提交表单的 Ajax POST 函数。在我的 beforeSend() 函数中,我有一个 sweetAlert 对话框,它将中止或继续 Ajax POST 调用。我的问题是成功函数在 beforeSend() 完成之前触发,即它不会等待用户选择 sweetAlert 对话框中的选项之一。如何在 sweetAlert 对话框完成之前暂停 Ajax 调用?
$.ajax({
method: "POST",
url: url,
data: data,
beforeSend: function(data) {
swal({
buttons: ["No", "Yes"],
successMode: true,
}).then((yes) => {
if (yes) {
swal("Success", {
icon: "success",
buttons: false,
});
} else {
data.abort()
}
});
},
success: function(data) {
// success functions
},
});
【问题讨论】:
标签: javascript html ajax forms sweetalert