'How to send manual payload in jQuery Datatable?

I was working on jQuery data table without server-side caching and pagination earlier, but now I am getting API that is performing server-side pagination searching and sorting.

I have some idea about server-side functionality provided by data table but my question is how can I pass my own parameters to ajax request, I have noticed that jQuery Datatable sends a payload that contains many things but I need to send some extra information as well to the backend.

My Code-

 $('#dataTable').ready(function () {
    $('#datatable').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax":{
    "url": "API/GetDetails",
    "dataType": 'json',
    "type": "GET",
    "beforeSend": function(xhr){
     xhr.setRequestHeader("Authorization",
    "Bearer Token");
   }
  }
});

})

Is there any way to change the payload values sent to the backend while making Api request? If yes how and where I should need to edit the code.



Solution 1:[1]

You can send custom http variables as per their documentation

https://datatables.net/examples/server_side/custom_vars.html

ex:

$(document).ready(function() {
$('#example').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url": "scripts/server_processing.php",
        "data": function ( d ) {
            d.myKey = "myValue";
            // d.custom = $('#myInput').val();
            // etc
        }
    }
} );

} );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 localhost