0

我正在发出一个 jquery ajax 请求如下

编辑

单击编辑 btn

$('.mymodalbtn').click(function($this){
            var id = $this.data('id'); 
            $('[name="id"]').val(id);
        });
    });

模态窗口打开可编辑字段,在提交表单时,我正在进行 ajax 调用,如下所示

$('#mymodalForm').on('submit',function(e){
            e.preventDefault();
            var successFlag=false;

            $.ajax({
                url: "/student/"+selectedId ,
                data : {'id':selectedId},
                type: 'PUT',
                datatype: "json",
                success: function(data){
                    $.gritter.add({
                        title: "Student",
                        text: data,
                        time: '1000'
                    }),
                }
            });
        });

<!-- Nifty Modal HTML -->
    <div class="md-modal colored-header md-effect-9" id="mymodalWin">
        <div class="md-content">
            <div class="modal-header">
                <h3>Student</h3>
            </div>
            <form id="mymodalForm" method="post" action="">
            <div class="modal-body form">   
                <input type="text" value="2" name="id"/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default btn-flat md-close" data-dismiss="modal">Cancel</button>
                <button type="submit" class="btn btn-primary btn-flat" id="edit-selected-transaction" data-dismiss="modal">Submit</button>
            </div>
            </form>
        </div>
    </div>
    <div class="md-overlay"></div>  

如果成功,我正在尝试自动关闭模式窗口,否则会显示错误并停留在模式窗口上。

我尝试了 .complete 但没有运气似乎有问题!

我也尝试过 .hide() ,但是单击编辑按钮时不会出现模态窗口。有人可以告诉我如何自动关闭引导模式窗口。

4

2 回答 2

0

如果您想在成功回调中自动关闭模式窗口,那么只需执行

$.ajax({
 success:function(data){
   $('#mymodal').modal('hide');
   // Rest of your code.
  }
});
于 2015-12-29T23:26:45.713 回答
0

Within your ajax call, use it like this....

$.ajax({
 success:function(data){
   $.gritter.add({
         title: "Student",
         text: responseHTML,
         time: '1000'
    },
 complete: function(){
            $('#mymodal').hide();
            //Here, you are executing your event loop, or in this example the api "hide" for the "#mymodal" id element.
    }
}); // I forgot a bracket here, my apologies.
于 2015-12-29T23:38:00.493 回答