简体   繁体   English

在Laravel上提交表单后如何关闭Bootstrap Modal?

[英]How to close Bootstrap Modal after submit form on Laravel?

Im export excel using bootstrap modal but after submit my modal not close. 我使用引导程序模态导出Excel,但是提交我的模态后无法关闭。 i have to manually close. 我必须手动关闭。

<button type="button" id="taxModal" class="btn btn-primary btn-group-xs">INVOICE SUMMARY</button>

<div id="taxesModal" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">GENERATE TAX INVOICE</h4>

                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ url('/invoice') }}">
                        {!! csrf_field() !!}

                        <div class="form-group{{ $errors->has('start_date') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">START DATE</label>

                            <div class="col-md-6">
                                <input type="date" class="form-control" name="start_date">

                                @if ($errors->has('start_date'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('start_date') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('end_date') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">END DATE</label>

                            <div class="col-md-6">
                                <input type="date" class="form-control" name="end_date">

                                @if ($errors->has('end_date'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('end_date') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>
                        <div class="form-group ">
                            <div class="col-md-3 col-md-offset-3">
                                <button type="submit" class="btn btn-primary form-control" id="btnSubmit" >Submit</button>
                            </div>
                            <div class="col-md-3">
                                <button type="button" class="btn btn-danger form-control" data-dismiss="modal">Close</button>
                            </div></div>
                    </form>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->

from my contoller im generating Excel document successfully but my modal not closeing after submit. 从我的contoller即时生成Excel文档,但是提交后我的模式没有关闭。 i tired data-dismiss="modal" in my button but modal will close before submit the form. 我在按钮上厌倦了data-dismiss="modal" ,但是modal将在提交表单之前关闭。 in my controller i tried return rediect(); 在我的控制器中,我尝试return rediect(); that is also dosn't work. 那也是行不通的。 im open this modal using below script 我使用以下脚本打开此模式

$(document).ready(function () {
        $("#taxModal").click(function () {
            $("#taxesModal").modal('show');
        });

    });

My Controller function 我的控制器功能

 public function invoice_create()
    {
     $start = Input::get('start_date');
     $end = Input::get('end_date');
    Excel::create('INVOICE SUMMERY', function($excel) use($sum,$tot,$start,$end)    {
$excel->sheet($start.'_'.$end, function($sheet) use($sum,$tot,$start,$end){
})->export('xls');
}}

My Route : 我的路线:

Route::post('invoice','HvAccountController@invoice_create');

In submit event close your modal. 在提交事件中,关闭您的模态。

    $(document).on("click","#btnSubmit",function (event) {
        ajaxCall();
    });

    function ajaxCall() {
       $.ajax({
           url : 'example.com',
           type: 'GET',
           success : resData
       })
     }

   function resData(data){
        $("#taxesModal").modal('hide');
   }

You can do this with some jQuery: 您可以使用一些jQuery来做到这一点:

$('#btnSubmit').on("click", function(event) {
    // submit form via ajax, then

    event.preventDefault();
    $('#taxesModal').modal( 'hide' );
});

You would just need to write an AJAX call to send the form data off to the right place to be processed. 您只需要编写一个AJAX调用即可将表单数据发送到正确的位置进行处理。 Something like this would do the trick: 这样的事情可以解决问题:

$.ajax({
      url: "{{ url('/invoice') }}",
      method: "POST",
      data: { //Your data to send - needs to include CSRF token
      }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM