doudun2212 2016-05-11 22:33
浏览 46
已采纳

单击使用ajax提交后关闭显示模式对话框

I have problem with reveal modal from zurb-foundation.

the modal dialog doesn't disappear after I click the submit button .

so it stays open after clicking the submit, and there's no way to close it unless if I refresh the page.

This's the reveal modal

    <div class="insert_post" data-open="add_post">
     <i class="fa fa-plus" ></i>
 </div>

 <div class="small reveal" id="add_post" data-reveal-id="myModal" data-reveal >
<?php
     $output .='


         <div class="row">
             <div class="medium-6 columns">
                 <label>First name
                     <input type="text"  id="first_name" contenteditable>
                 </label>
             </div>
             <div class="medium-6 columns">
                 <label>Last name
                     <input type="text"  id="last_name" contenteditable>
                 </label>
             </div>
              <button type="button" name="btn_add" id="btn_add" class="button btn btn-xs btn-success" >Submit</button> 
         </div>






     ';
     echo $output; ?>
     <button class="close-button" data-close aria-label="Close modal" type="button">
         <span aria-hidden="true">&times;</span>
     </button>
 </div>

Jquery/ajax code to insert into the database.

$(document).ready(function(){
    function fetch_data()
    {
        $.ajax({
            url: "includes/home.php",
            method:"POST",
            success:function(data){
                $('#container').html(data);
            }
        });
    }
    fetch_data();
    $(document).on('click', '#btn_add', function(){
        var first_name = $('#first_name').val();
        var last_name = $('#last_name').val();

        $.ajax({
            //url:"includes/widgets/insert.php",
            method:"POST",
            data:{first_name:first_name, last_name:last_name},
            dataType:"text",
            success:function(data)
            {
                //alert(data);
                fetch_data();
            }
        })

    });

});
</script>

Picture of the problem http://s32.postimg.org/yqbuz1rvp/wewewewe.png. after I submit the form!

  • 写回答

1条回答 默认 最新

  • douge3113 2016-05-12 07:26
    关注

    You can close the modal by JavaScript in the success call back.

    $("#add_post").foundation('close');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退