weixin_33698823 2016-07-12 08:56 采纳率: 0%
浏览 12

警报框不起作用

I am trying to display an alert box and click on Ok to refresh the page. I have tried using window.location.reload(true)

I want to show a message before page reload. The problem is that the page reloads automatic but the alert box not showing.

HTML Content

<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 Code:

$.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){
            }
        });

Action

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;
    }
}
  • 写回答

2条回答 默认 最新

  • 妄徒之命 2016-07-12 09:00
    关注

    You have to use bootbox callback :

    bootbox.alert("Password changed successfully.", function() {
        // any code you want to happen after the alert is dismissed
       window.location.reload(true);
    });
    

    So it will be :

    ...
    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.');
        }
    },
    ...
    

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵