且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用新参数重新加载 Ajax 请求

更新时间:2023-12-05 18:42:22

您可以使用函数作为 ajax.data 选项如下图.

You can use function as a value for ajax.data option as shown below.

这样,您的代码将在每次客户端向服务器发出请求时运行,而不是像初始代码那样运行一次.

That way your code will be run every time the client makes request to the server and not once as with your initial code.

$('#table1').DataTable({
   "serverSide": true,
   "ajax": {
      "url": "Home/Search",
      "type": "POST",
      "data": function(d){
         d.searchType = GetSearchType();
         d.searchText = GetSearchText();
      }
   }
});

然后在需要重新加载表格时使用$('#table1').DataTable().ajax.reload()$('#table1').DataTable().ajax.reload(null, false) 如果你不想重置当前页面.请参阅 ajax.reload() 了解更多信息信息.

Then use $('#table1').DataTable().ajax.reload() when you need to reload the table or $('#table1').DataTable().ajax.reload(null, false) if you don't want to reset the current page. See ajax.reload() for more information.