首页 > 解决方案 > AJAX 响应后数据表未更新

问题描述

我正在执行 ajax 调用,但数据表在响应后没有更新。我已经尝试了几个功能。请注意,我使用 jQuery 版本 2.2.4

$.ajax({
        type: 'POST',
        url: URL,
        data: parsed,
        dataType: "json",
        beforeSend: function() {}

    }).done(function(data) {
        let Content = '';
        $("#order-table-data").html(Content);
        $("#datatable").trigger("update");
        $("#datatable").ajax.reload(); //Cannot read property 'reload' of undefined
    })

html:

   <table id="datatable" class="table table-striped table-bordered">
     <thead>
     <tr>
                <th>Product</th>
                <th>Stock</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Order</th>
     </tr>
     </thead>

         <tbody id="order-table-data"></tbody>
     </table>              

标签: javascriptjquerydatatables

解决方案


这可能会帮助你

$("#datatable").DataTable().ajax.reload(null, false );

或者

$("#datatable").ajax.reload(null, false);

推荐阅读