Reload Ajax request with new parameters

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();
      }
   }
});

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.


$('#table1').DataTable().ajax.url("?some_param=1&another=2").load();

This is an another solution. Add your params inside default datatable params.

How to set dynamically the Ajax URL of a dataTable?