草庐IT

javascript - 警告框不起作用

coder 2024-04-10 原文

我正在尝试显示一个警告框并单击“确定”刷新页面。我试过使用 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){
            }
        });

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;
    }
}

最佳答案

你必须使用 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.');
    }
},
...

希望这对您有所帮助。

关于javascript - 警告框不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38324203/

有关javascript - 警告框不起作用的更多相关文章

  1. ruby - 在院子里用@param 标签警告 - 2

    我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?

  2. ruby-on-rails - active_admin 目录中的常量警告重新声明 - 2

    我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA

  3. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  4. ruby-on-rails - 启动 Rails 服务器时 ImageMagick 的警告 - 2

    最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru

  5. ruby-on-rails - 我更新了 ruby​​ gems,现在到处都收到解析树错误和弃用警告! - 2

    简而言之错误:NOTE:Gem::SourceIndex#add_specisdeprecated,useSpecification.add_spec.Itwillberemovedonorafter2011-11-01.Gem::SourceIndex#add_speccalledfrom/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91./opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in`==':und

  6. ruby-on-rails - "assigns"在 Ruby on Rails 中有什么作用? - 2

    我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o

  7. ruby-on-rails - 使用 javascript 更改数据方法不会更改 ajax 调用用户的什么方法? - 2

    我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的

  8. ruby - 字符串文字前面的 * 在 ruby​​ 中有什么作用? - 2

    这段代码似乎创建了一个范围从a到z的数组,但我不明白*的作用。有人可以解释一下吗?[*"a".."z"] 最佳答案 它叫做splatoperator.SplattinganLvalueAmaximumofonelvaluemaybesplattedinwhichcaseitisassignedanArrayconsistingoftheremainingrvaluesthatlackcorrespondinglvalues.Iftherightmostlvalueissplattedthenitconsumesallrvaluesw

  9. ruby - 为什么这个 eval 在 Ruby 中不起作用 - 2

    你能解释一下吗?我想评估来自两个不同来源的值和计算。一个消息来源为我提供了以下信息(以编程方式):'a=2'第二个来源给了我这个表达式来评估:'a+3'这个有效:a=2eval'a+3'这也有效:eval'a=2;a+3'但我真正需要的是这个,但它不起作用:eval'a=2'eval'a+3'我想了解其中的区别,以及如何使最后一个选项起作用。感谢您的帮助。 最佳答案 您可以创建一个Binding,并将相同的绑定(bind)与每个eval相关联调用:1.9.3p194:008>b=binding=>#1.9.3p194:009>eva

  10. ruby-on-rails - Spring 不起作用。 [未初始化常量 Spring::SID::DL] - 2

    我无法运行Spring。这是错误日志。myid-no-MacBook-Pro:myid$spring/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/lib/spring/sid.rb:17:in`fiddle_func':uninitializedconstantSpring::SID::DL(NameError)from/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/li

随机推荐