我正在尝试显示一个警告框,然后单击“确定”以刷新页面。我尝试过使用window.location.reload(true)
我想在页面重新加载之前显示一条消息。问题是页面自动重新加载但警告框没有显示。
HTML内容
<form action="<?php echo $action_link; ?>" method="post" name="form_Change_Password" id="form_Change_Password" class="form-horizontal" novalidate="novalidate">
<input type="hidden" name="id" value="<?php echo $admin_id; ?>">
<div class="form-body">
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button> You have some form errors. Please check below.
</div>
<div class="alert alert-success display-hide">
<button class="close" data-close="alert"></button> Your form validation is successful!
</div>
<div class="form-group margin-top-20">
<label class="control-label col-md-3">Old Password
<span class="required" aria-required="true"> * </span>
</label>
<div class="col-md-4">
<div class="input-icon right">
<i class="fa"></i>
<input type="password" class="form-control" name="old_password" id="old_password" value="">
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">New Password
<span class="required" aria-required="true"> * </span>
</label>
<div class="col-md-4">
<div class="input-icon right">
<i class="fa"></i>
<input type="password" class="form-control" name="new_password" id="new_password" value="">
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Confirm Password
<span class="required" aria-required="true"> * </span>
</label>
<div class="col-md-4">
<div class="input-icon right">
<i class="fa"></i>
<input type="password" class="form-control" name="confirm_password" id="confirm_password" value="">
</div>
</div>
</div>
</div>
<div class="form-actions">
<div class="row">
<div class="col-md-offset-3 col-md-9">
<button type="button" class="btn green" name="btnChangePassword" onclick="newpassword(<?php echo $admin_id; ?>)">Update</button>
<a href="<?php echo $admin_url; ?>index.php?file=a-admin_profile" class="btn default">Cancel</a>
</div>
</div>
</div>
</form>
Ajax代码:
$.ajax({
url: "<?php echo $action_link; ?>",
type: "POST",
data: {
'id': <?php echo $admin_id; ?>,
'old_pass': old_pass,
'new_pass': new_pass,
'conf_pass': conf_pass,
change_password : 'change_password'
},
success: function (result){
if(result == 1){
bootbox.alert('Password changed successfully.');
window.location.reload(true);
}else if(result == 2){
bootbox.alert('New password and confirm password does not match.');
return false;
}
else if(result == 0){
bootbox.alert('Old password does not match.');
}
},
error: function (result){
}
});
动作
if(isset($_REQUEST['change_password']) && $_REQUEST['change_password'] == 'change_password'){
ob_get_clean();
$id = $_REQUEST['id'];
$password = mysqli_real_escape_string($obj->CONN,md5($_REQUEST['old_pass']));
$dbpassword = $admin->select_password($id);
$newpass = $_REQUEST['new_pass'];
$confpass = $_REQUEST['conf_pass'];
if($dbpassword != $password){
echo 0; exit;
}elseif($newpass != $confpass){
echo 2; exit;
}
else{
$admin->update_password($id, md5($newpass), $current_date);
echo 1; exit;
}
}
答案 0 :(得分:6)
您必须使用 bootbox callback
:
bootbox.alert("Password changed successfully.", function() {
// any code you want to happen after the alert is dismissed
window.location.reload(true);
});
所以它会是:
...
success: function (result){
if(result == 1){
bootbox.alert("Password changed successfully.", function() {
window.location.reload(true);
});
}else if(result == 2){
bootbox.alert("New password and confirm password does not match.", function() {
return false;
});
}else if(result == 0){
bootbox.alert('Old password does not match.');
}
},
...
希望这有帮助。
答案 1 :(得分:5)
尝试使用以下内容:
bootbox.alert('Password changed successfully.', function(){
window.location.reload(true);
});
而不是:
bootbox.alert('Password changed successfully.');
window.location.reload(true);