我需要运行一个ajax函数后,确认是按启动框确认模式。模式短暂闪烁,然后php代码无需等待即可运行。我如何让它等待。
当我删除bootbox时,我的Javascript会运行,但我想在运行之前进行确认
我的代码是,
$('#change_pass_form').submit(function () {
bootbox.confirm({
message: "Your password is about to be changed. Are you sure?",
buttons: {
cancel: {label: '<i class="fa fa-times"></i> Cancel'},
confirm: {label: '<i class="fa fa-check"></i> Confirm'}
},
callback: function (result) {
if (result === 'true') {
$.ajax({
type: 'POST',
url: 'php_files/profile_php_files/profile_password_change_process.php',
data: {
user_id: sessionStorage.getItem('user_id'),
new_password: $('#new_password').val(),
repeat_password: $('#repeat_password').val()
},
success: function (data) {
if (data === 'correct') {
bootbox.alert({
size: 'small',
message: 'Your password has been changed. You will now be logged out.',
callback: function () {
window.location.replace('index.html');
}
});
return true;
} else {
bootbox.alert({
size: 'small',
message: data
});
return false;
}
}
});
} else {
return false;
}
}
});
}); 发布于 2017-08-07 01:52:23
所有的return false和return true都返回到回调函数,而不是外部的提交处理函数。此外,它们只在异步事件之后发生,因此不会阻止默认的提交过程。
只需阻止默认浏览器提交
$('#change_pass_form').submit(function (event) {
event.preventDefault();https://stackoverflow.com/questions/45534539
复制相似问题