【问题标题】:How to reload datatable after form submit in laravel?如何在 laravel 中提交表单后重新加载数据表?
【发布时间】:2020-12-27 09:24:24
【问题描述】:

你好,我正在使用 laravel 构建一个项目,我将多个数据从 CategoryController 传递到 Category Blade 文件,但问题是当我插入数据时它已成功插入,我想用新记录重新加载数据表但是我现有的 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 的初学者,正在尝试学习,请以最好的方式帮助我。

【问题讨论】:

    标签: jquery ajax laravel datatable


    【解决方案1】:

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

    阅读实际问题here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      相关资源
      最近更新 更多