首页 > 解决方案 > 如何在 laravel 中提交表单后重新加载数据表?

问题描述

你好我正在用laravel构建一个项目,我将多个数据从CategoryController传递到Category刀片文件,但问题是当我插入数据时它已成功插入,我想用新记录重新加载数据表但我现有的id 为 example1 的表正在进入另一个 id 为 example1 的表中,为什么?这是我的代码...

脚本

$("#example1").DataTable();

$(document).on('submit','.database_operation',function(e){
    e.preventDefault();
    var url = $(this).attr('action');
    var data = $(this).serialize();
    $.ajax({
        url:url,
        method:"POST",
        data:data,
        success:function(fb){
            var resp = $.parseJSON(fb);
            // console.log(resp);
            if(resp.status=='true'){
                toastr.success(resp.message,'Success');
                $('#myModal').hide();
                $('.modal-backdrop').remove()
                $(document.body).removeClass("modal-open");
                $('#example1').DataTable().clear().destroy();
                $("#example1").DataTable();
                $("#example1").load(" #example1");
            }else if(resp.status=='false'){
                    
                $.each( resp.message, function( key , value ) {
                toastr.error(value + '<br>','Error');
                });
                

            }else if(resp.status=='false-1'){
                toastr.error(resp.message,'Error');
            }
            
            
        }

    });
    
    return false;
});

嘿,我是 laravel 和 jquery 的初学者,正在尝试学习,请以最好的方式帮助我。

标签: jqueryajaxlaraveldatatable

解决方案


尝试添加 $('#example1').DataTable().ajax.reload(); 在响应状态为真之后。

在此处阅读实际问题


推荐阅读