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 Unity发布gzip压缩的webgl之后让浏览器可以正常显示画面
  • ¥15 有没有人知道这种提示怎么关?现在不做ts项目了不知道咋关了,求解,现在我以前的js项目都是这种提示了
  • ¥15 为什么mysql做了碎片化处理data_free还是很高
  • ¥15 single positional indexer is out-of-bounds
  • ¥15 LSTM 模型数据量需要多少?
  • ¥15 mysql数据抓包开发报表
  • ¥15 linux系统下安装office打不开
  • ¥20 rsync脚本分发错误,文件不齐全
  • ¥15 labview顺序结构与时间延时
  • ¥15 脚本求解,源于数据库脚本变量筛选。