【问题标题】:hide pop up based on message under browser's Response tab根据浏览器响应选项卡下的消息隐藏弹出窗口
【发布时间】:2017-05-05 22:15:34
【问题描述】:

在弹出框中,我们正在显示登录表单。一旦用户输入错误的电子邮件 ID 或密码,我们将显示消息:无效登录/密码,但一旦他们输入正确的详细信息并单击登录按钮,用户就会登录。

但问题是弹出框将一直存在,直到我们通过关闭按钮手动关闭弹出框,如下图所示,但如果登录成功,我想隐藏弹出框。

enter image description here

一旦我们点击登录,在 Response 选项卡下,如果没有消息,我想隐藏弹出窗口,如果有消息为 success":false,"error":"Invalid login or password.",我不想隐藏弹出窗口

enter image description here

我试过下面的代码:

HTML

<form>
//code for email and pw
<button onclick = "hideWindow()">Login</button>
</form>

Ajax

 function hideWindow() 
                { 

                var username=jQuery( "#customusername" ).val();
                var password=jQuery( "#custompassword" ).val();

                 url="";
                 new Ajax.Request(url, {
                 method: 'POST', 
                 onFailure: function(response){
                 },
                parameters: {
                username: username,
                password:password               
                },
                 onSuccess: function(response)
                 { 
                    if(response.responseText=="")
                    {
                        //trigger to close popup

                        document.getElementById('something').style.display = 'none'; 
                        document.getElementById('ajaxlogin-mask').style.display = 'none';
                    }

                 }
                });
              }

编辑

<div class="ajaxlogin-window" id="something">         
       <form>
            <div class="content">
                <ul class="form-list">
                    <li>
                    <input type="hidden" id="likeproduct_id" name="product_id" value=""/>
                        <label for="email" class="required"><em>*</em>Email</label>
                        <div class="input-box">
                            <input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email"  title="<?php echo $this->__('Email Address') ?>" />
                        </div>
                    </li>
                    <li>
                        <label for="pass" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
                        <div class="input-box">
                            <input type="password" name="login[password]"  id="pass" title="<?php echo $this->__('Password') ?>" />
                        </div>
                    </li>
                    <?php echo $this->getChildHtml('form.additional.info'); ?>
                </ul>
            </div>
            <div class="buttons-set">                       
           <button onclick = "hideWindow()" type="submit" class="button" title="<?php echo $this->__('Login') ?>" name="send" id="send2"  ><span><span><?php echo $this->__('Login') ?></span></span></button>
            </div>
</div>      

【问题讨论】:

  • 能不能把问题的html部分加进去。对您有帮助会很有帮助
  • 用html代码更新问题,请看看.....
  • 我正在使用这个 ajax 代码:pasted.co/48186abb

标签: browser


【解决方案1】:

我可以看到你的 ajax 函数有问题,试试这个:

onSuccess: function(response) 
{ 
  document.getElementById('something').style.display = 'none'; 
  document.getElementById('ajaxlogin-mask').style.display = 'none'; 
}

【讨论】:

    【解决方案2】:

    function hideWindow() 
      { 
      var db_username = 'ankit';
      var db_password = 'password';
      var username=jQuery( "#customusername" ).val();
      var password=jQuery( "#custompassword" ).val();
      if(username = db_username && password == db_password) {
        jQuery('#something').hide();
      }
      else{
        jQuery('#something').prepend('Wrong Cred ');
      }
    
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="ajaxlogin-window" id="something">         
           <form>
                <div class="content">
                    <ul class="form-list">
                        <li>
                        <input type="hidden" id="likeproduct_id" name="product_id" value=""/>
                            <label for="email" class="required"><em>*</em>Email</label>
                            <div class="input-box">
                                <input type="text" name="login[username]" value="" id="email"  title="Email Address" />
                            </div>
                        </li>
                        <li>
                            <label for="pass" class="required"><em>*</em>Password</label>
                            <div class="input-box">
                                <input type="password" name="login[password]"  id="pass" title="Password" />
                            </div>
                        </li>
    
                    </ul>
                </div>
                <div class="buttons-set">                       
               <button onclick = "hideWindow()" type="submit" class="button" title="Login" name="send" id="send2"  ><span><span>Login</span></span></button>
                </div>

    请检查代码而不是 ajax 调用,我刚刚添加了一个 if 条件。 希望它可以帮助你 谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-11
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 2012-03-14
      相关资源
      最近更新 更多