使用ajax动态刷新jquery数据表

时间:2016-01-28 00:41:31

标签: javascript jquery ajax datatables

有没有办法可以自动刷新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);
        }
    });
});

然而,这使我的表无法重新初始化'错误......有人可以帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

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