duanqiangwu9332 2016-10-27 08:53
浏览 67
已采纳

在数据库中插入后关闭Modal引导程序窗口

I have modal bootstrap window that insert data in database using AJAX and JQUERY but I couldn't close window after insert and I want also to show message like Successfully inserted see below code

---- modal window ----

    <!-- Modal  employer-->
<div class="modal fade" id="employer" tabindex="-1" role="dialog" 
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <button type="button" class="close" 
                   data-dismiss="modal">
                       <span aria-hidden="true">&times;</span>
                       <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">

                </h4>
            </div>

            <!-- Modal Body -->
            <div class="modal-body">

                <form role="form" action='insert.php' method='post' id='myform'>
                  <div class="form-group">
                    <label for="exampleInputEmail1">Nom</label>
                      <input type="text"  name="nom"class="form-control"
                      id="exampleInputEmail1" placeholder="Nom"/>
                  </div>
                  <div class="form-group">
                    <label for="exampleInputPassword1">Prenom</label>
                      <input type="text" name="prenom" class="form-control"
                          id="exampleInputPassword1" placeholder="Prenom"/>
                  </div>
                                    <div class="form-group">
                    <label for="exampleInputPassword1">telephone</label>
                      <input type="text" name="telephone"class="form-control"
                          id="exampleInputPassword1" placeholder="telephone"/>
                  </div>
      <div class="form-group">
                    <label for="exampleInputPassword1">Fonction</label>
                      <input type="text" name="fonction" class="form-control"
                          id="exampleInputPassword1" placeholder="Fonction"/>
                  </div>
                      <div class="form-group">
                    <label for="exampleInputPassword1">Salire</label>
                      <input type="text" name="salaire" class="form-control"
                          id="exampleInputPassword1" placeholder="Salire"/>
                  </div>




            </div>

            <!-- Modal Footer -->
            <div class="modal-footer">

                <button type="button" id='insert' class="btn btn-primary">
                    Save changes
                </button>
                  </form>
            </div>
        </div>
    </div>
</div>

---- insert.php ----

<?php
require('config.php');
 $nom = $_POST['nom'];
 $prenom = $_POST['prenom'];
  $telephone = $_POST['telephone'];
   $fonction = $_POST['fonction'];
    $salaire = $_POST['salaire'];
 $sql = "insert into employer (nom, prenom,telephone,fonction,salaire) values ('$nom','$prenom','$telephone','$fonction','$salaire')";

 if(mysqli_query($con, $sql)){
 echo 'success';
?>



 <script type="text/javascript">
$(document).ready(function(){

        $('#employer').modal('hide');

});
</script>
 <?php

  }
?>

---- insert.js----

 $('#myform').submit(function(){
    return false;
});

$('#insert').click(function(){
    $.post(     
        $('#myform').attr('action'),
        $('#myform :input').serializeArray(),
        function(result){
            $('#result').html(result);
        }
    );
});
  • 写回答

2条回答 默认 最新

  • duanchao9559 2016-10-27 08:59
    关注

    When you get your response from ajax request then close modal window.

        $('#employer').modal('hide');
    

    As according to your example:

    $('#insert').click(function(){
        $.post(     
            $('#myform').attr('action'),
            $('#myform :input').serializeArray(),
            function(result){
                $('#employer').modal('hide'); // ADD CODE FOR CLOSE MODAL
                $('#result').html(result);
            }
        );
    

    });

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题