doujing2017 2014-10-15 11:24
浏览 46
已采纳

如何在按下按钮时禁用模态关闭

I'm trying to create a login form in modal window. The problem is when I click on the sign in button, and if the login credentials are wrong, the modal closes. User needs to click again on the sign in button to see the modal and the error message.

How can I solve this?

This is the modal content.

<div id="signin" class="modal fade">
  <div class="modal-dialog">
                <?php include "view/login.html";  ?>
   </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

login.html file.

<section class="frontoffice" style="padding: 20px 0;">
    <div class="">
        <h3 class="text-center" style="font-weight:700">SIGN IN</h3>
        <div class="row">
        <form action="" method="POST">
            <div class="col-md-1">
            </div>
            <div class="col-md-10 request-form">
                <div class="form-area">
                    <div class="row">
                        <div class="col-md-12">
                            <input class="text-field" name="username" type="text" placeholder="Username*" style="width:100%">
                            <?php echo $unameerror; ?>
                            <input class="text-field" name="password" type="password" placeholder="Password*" style="width:100%">
                            <?php echo $passerror; ?>

                        </div>
                    </div>
                </div>
                <div class="row" style="margin:20px;">
                    <div class="col-md-12 text-center">
                        <input type="submit" value="SIGN IN" name="login" class="blueButton">
                    </div>
                </div>
            </div>
        <div class="col-md-1">
        </div>
        </form>
        </div>
    </div>
</section>

Javascript

<script type="text/javascript">
$(document).ready(function() {
    $("[rel='popup']").popover();
});

  • 写回答

1条回答 默认 最新

  • doubi2228 2014-10-15 11:46
    关注

    The <input type='submit'/> automatically posts a form, once pressed. So the page should be refreshed after button press. You should use ajax to send the form and post back the response. It should look like this:

    $(function(){
    
     $("form").on("submit", function(e){
      e.preventDefault();
      $.post("url", $(this).serialize(), function(response){
        //present errors
      }, "json");
      })
    })
    

    On the php side, set the response as an array, and use echo json_encode($array) to present the result.

    Hope i got it this time :D

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C