【问题标题】:How refresh datatable after ajax success in laravel?laravel ajax 成功后如何刷新数据表?
【发布时间】:2021-05-16 19:30:54
【问题描述】:

我使用数据表来显示我的数据。我将数据存储在 ajax 请求中并在成功响应后附加。数据附加成功。但问题是附加项目时数据表未更新。如果我重新加载页面,那么它可以工作。见图像红色标记。附加了数据,但未更新数据表。

这是我的 ajax 成功响应

 success: function(response) {
   if (response.status == true) {
      var href = "{{ route('home') }}/";
       $('#dataTable tbody').prepend( "<tr class='data" + response.data.id + "'>" +
           "<td><img src='" + href + "storage/sliders/" + response.data.image + "'></td>" +
            "<td>" + response.data.name + "</td>" +
            "<td>" + response.data.title+ "</td>" +
             "</tr>" ); 
           }
      }

ajax成功后如何自动刷新数据表?

【问题讨论】:

    标签: php jquery ajax laravel datatable


    【解决方案1】:

    尝试如下:-

    var table = $('#table_id').DataTable({
    
    //ajax method that gets data from databases. 
    
    });
    

    使用此方法刷新您的表格:

    table.ajax.reload();
    

    如果它给出类似的错误

    DataTables 警告:表 id=table_id- JSON 响应无效

    然后在向表中添加数据之前使用下面的函数来解决错误:

    table.clear()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 2021-04-22
      • 2018-05-09
      相关资源
      最近更新 更多