使用 ajax 动态刷新 jquery 数据表

Dynamically refresh jquery datatable using ajax

本文关键字:数据表 jquery 动态刷新 ajax 使用      更新时间:2023-09-26

有没有办法自动刷新jquery数据表中的数据?我想单击一个按钮,该按钮将发出 AJAX 请求以返回新数据并将数据插入数据表中。我想要这样的东西:

$("#update_button").click(function(e) {
    $.ajax({
        type: "POST",
        data: productType,
        url: "/api/getproducts",
        success: function(data, status) {
            $('#products_table').DataTable( {
                data: data,
                columns: [
                    { title: "col 1" },
                    { title: "col 2" },
                    { title: "col 3" },
                    { title: "col 4" },
                    { title: "col 5" },
                    { title: "col 6" }
                ]
            });
        },
        error: function(data, status, res) {
            console.log('error...');
            console.log(res);
        }
    });
});

但是这给了我"表无法重新初始化"错误...有人可以帮忙吗?

谢谢!

尝试这样的事情:

$("#myName").on("change", function(){
   tbl.ajax.url("<?php  echo RP_SSP ?>server_processing_reservTables.php?myName="+$(this).val()).load();
 });