我需要在启动箱确认模式上按下确认后运行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;
}
}
});
});
答案 0 :(得分:1)
所有return false
和return true
都返回回调而不是外部提交处理函数。此外,它们仅在异步事件之后发生,因此永远不会阻止默认提交过程。
只是阻止默认浏览器提交
$('#change_pass_form').submit(function (event) {
event.preventDefault();