简体   繁体   中英

How to avoid Uncaught (in promise) DOMException on ajax call?

I am getting error

Uncaught (in promise) DOMException

in html page. This error occurs when I am using Ajax call for store or other purpose. when i try to check this error on that page from inspect view console then it shows <!DOCTYPE html> .

For more information I am developing project on laravel that's front-end is Laravel Blade HTML Template and back-end is laravel. In some page in using normal form submission and some page I am using ajax call. My browser is Google Chrome latest version.

So that I am not able to know why this problem is happening?

I am sharing a screenshot of that please answer....

enter image description here

When I click on file subjects:1 then I come here

enter image description here

So I try to find my solution every where but could not find. Please tell me the reason why it is happening? What is better solution?

Code part -----

its header part is another file. it is only base file other jQuery or supporting file being load its before into another file... after load of that these all file being load. like dataTable etc. .

<table id="dt_basic" class="table table-striped table-bordered table-hover" width="100%">
<thead>
    <tr>
        <th>SL.</th>
        <th>SUBJECT CODE</th>
        <th>SUBJECT NAME</th>
        <th>COURSE</th>
        <th></th>
        <!-- check  Login -->
        <th></th>
        <!-- check  Login -->

    </tr>
</thead>
<tbody>
@if( count( $subjects ))
@foreach($subjects  as $key => $items )
    <tr>
        <td>{{ $key+1 }}</td>
        <td>{{ $items->SUBJECT_CODE }}</td>
        <td>{{ $items->SUBJECT_NAME }}</td>
        <td>{{\App\Helper\Utility::getCourseByCode($items->CATEGORY)}}</td>
        <td>
            <button type="button" class="btn btn-xs btn-success" onclick="EditSubject({{$items->ID}})">
                <i class="fa fa-edit"></i> Edit</button></td>
        <!-- check  Login -->
        <td><button type="button" class="btn btn-xs btn-danger" onclick="DeleteSubject({{ $items->ID}});">
                <i class="fa fa-remove"></i> Delete</button></td>
        <!-- check  Login -->
    </tr>
    @endforeach
@endif
</tbody>
</table>


<script src="{{ asset('js/plugin/datatables/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('js/plugin/datatables/dataTables.colVis.min.js') }}"></script>
<script src="{{ asset('js/plugin/datatables/dataTables.tableTools.min.js') }}"></script>
<script src="{{ asset('js/plugin/datatables/dataTables.bootstrap.min.js') }}"></script>
<script src="{{ asset('js/plugin/datatable-responsive/datatables.responsive.min.js') }}"></script>
<script type="text/javascript">


        /* BASIC ;*/
        var responsiveHelper_dt_basic = undefined;

        var breakpointDefinition = {
            tablet : 1024,
            phone : 480
        };

        $('#dt_basic').dataTable({
            "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>"+
            "t"+
            "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
            "iDisplayLength": 50,
            "preDrawCallback" : function() {
                // Initialize the responsive datatables helper once.
                if (!responsiveHelper_dt_basic) {
                    responsiveHelper_dt_basic = new ResponsiveDatatablesHelper($('#dt_basic'), breakpointDefinition);
                }
            },
            "rowCallback" : function(nRow) {
                responsiveHelper_dt_basic.createExpandIcon(nRow);
            },
            "drawCallback" : function(oSettings) {
                responsiveHelper_dt_basic.respond();
            }
        });

        function EditSubject(id)
        {
            $("#formModalTitle").html('<h4 class="modal-title">Subject Setting</h4>');
            $('#formModalBody').load("{{ url('setting/subjects/edit') }}","id="+id,function(e){
                $('#formModal').modal('show');
            });
        }

        function DeleteSubject(id)
        {
            $.SmartMessageBox({
                title : "<i class='text-danger fa fa-warning'></i> Caution!!",
                content : "Would you like to delete selected Subject?",
                buttons : '[No][Yes]'
            }, function(ButtonPressed) {
                if (ButtonPressed === "Yes") {
                    $.ajax({
                        type: 'GET',
                        url: "{{ url('setting/subjects/delete') }}",
                        data: {id: id},
                        dataType: "json",
                        success: function (data) {
                            if (data.message) {
                                $.smallBox({
                                    title: "Message",
                                    content: "<i class='fa fa-info-circle'></i> <i>" + data.message + "</i>",
                                    color: "#659265",
                                    iconSmall: "fa fa-check fa-2x fadeInRight animated",
                                    timeout: 4000
                                });
                                $('#showDivSubject').load("{{ url('setting/subjects/list') }}");
                            }
                        } ,
                        error:function (data){
                            $.smallBox({
                                title: "Message",
                                content: "<i class='fa fa-clock-o'></i> <i>" + data.responseJSON.errors.subject_code[0] + "</i>",
                                color: "#C46A69",
                                iconSmall: "fa fa-times fa-2x fadeInRight animated",
                                timeout: 4000
                            });
                        }

                    });
                }
            });
        }

</script>

If you are using Promise you must use syntax as :

var P = new Promise(/*something*/);

P.then(
       doSomeThing();
        }).catch(
        function(reason) {
            console.log(reason);
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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