Laravel5.8中重复ajax请求的问题

时间:2019-06-03 10:32:22

标签: javascript jquery ajax

当我单击check-document时,ajax请求运行,但是我不知道为什么重复此请求,并且每当我关闭模式时,它都会再次打开

ajax代码:

var id;
$('.check-document').click(function(e) {
    id = $(this).attr("id-document");
    var block = $(this).closest('.card');
    e.preventDefault();
    $(block).block({
        message: '<span class="font-weight-semibold"><i class="icon-spinner4 spinner mr-2"></i>&nbsp;please wait...</span>',

        overlayCSS: {
            backgroundColor: '#fff',
            opacity: 0.8,
            cursor: 'wait'
        },
        css: {
            border: 0,
            padding: '10px 15px',
            color: '#fff',
            width: 'auto',
            '-webkit-border-radius': 3,
            '-moz-border-radius': 3,
            backgroundColor: '#333'
        }
    });

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $.ajax({
        url: "{{route('admin.auth.document.show')}}",
        type: 'POST',
        dataType: 'json',
        data: {
            id: id,
        },
        success: function(result) {
            if (result.type == 'success') {
                $(".card").unblock();
                $('#check-document').modal('show');
            } else {
                $(".card").unblock();
                Swal({
                    title: "error !!",
                    confirmButtonText: "خب",
                    buttonsStyling: true,
                    type: "error"
                });
            }

        },
        error: function(xhr) {
            //the status is in xhr.status;
            //the message if any is in xhr.statusText;
        }
    });
});

模式:

<div id="check-document" class="modal fade check-document" data-backdrop="false" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">edit card</h5>
                <button type="button" class="close close-modal" data-dismiss="modal">&times;</button>
            </div>

            <div class="modal-body">
                <div class="alert alert-warning border-0 alert-dismissible any-errors" id="any-errors"
                    style="display:none">


                </div>
            </div>
        </div>
    </div>
</div>

和按钮:

 <a href="#" class="btn btn-primary check-document" id-document="13" name="check-document">see</a>

0 个答案:

没有答案