gpt4 book ai didi

javascript - 使用ajax动态刷新jquery数据表

转载 作者:行者123 更新时间:2023-12-01 05:34:13 24 4
gpt4 key购买 nike

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

关于javascript - 使用ajax动态刷新jquery数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35050935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com