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 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类