等待 Bootbox 确认 运行 Ajax
Wait for Bootbox Confirm to Run Ajax
在启动框确认模式上按下确认后,我需要 运行 一个 ajax 函数。模态一闪而过,然后php代码是运行,没有等待。怎么让它等。
我的 Javascript 运行s 当我删除 bootbox 但我想在它 运行
之前确认
我的代码是,
$('#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;
}
}
});
});
所有 return false
和 return true
都返回到回调,而不是外部提交处理函数。此外,它们仅在异步事件之后发生,因此永远不会阻止默认提交过程。
只是阻止默认浏览器提交
$('#change_pass_form').submit(function (event) {
event.preventDefault();
在启动框确认模式上按下确认后,我需要 运行 一个 ajax 函数。模态一闪而过,然后php代码是运行,没有等待。怎么让它等。
我的 Javascript 运行s 当我删除 bootbox 但我想在它 运行
之前确认我的代码是,
$('#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;
}
}
});
});
所有 return false
和 return true
都返回到回调,而不是外部提交处理函数。此外,它们仅在异步事件之后发生,因此永远不会阻止默认提交过程。
只是阻止默认浏览器提交
$('#change_pass_form').submit(function (event) {
event.preventDefault();