How to post the parameter in ajax call of jquery datatable
Just pass it like a normal jQuery ajax in POST fashion.
The structure should look like this:
ajax: { type: 'POST', url: <path>, data: { your desired data } }
Example:
var $table = $('#example').dataTable( "processing": true, "serverSide": true, "bDestroy": true, "bJQueryUI": true, "ajax": { 'type': 'POST', 'url': 'getResult.php', 'data': { formName: 'afscpMcn', action: 'search', // etc.. }, }});
In PHP, just access the POST indices as usual (just the straightforward approach):
getResult.php
$form_name = $_POST['formName'];// the rest of your values ...
You can try this way:
$('#example').dataTable( { "ajax": { "url": "data.json", "data": function ( d ) { d.extra_search = $('#extra').val(); } }});
$("#tbl").dataTable({ oLanguage: { sProcessing: '<div id="loader"></div>' }, bProcessing: true, "bServerSide": true, "iDisplayLength": pageSize, "sAjaxSource": " /PurchaseOrder/AddVendorItems", // url getData.php etc "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) { aoData.push({ "name": "where", "value": ID +" AND ISNULL(IsFinal,0) = "+ ($("#chkFinal").bootstrapSwitch('state') == true ? 1 : 0) }); aoData.push({"name": "PackIDFK", "value": $("#PackIDFK").val()}) //pushing custom parameters oSettings.jqXHR = $.ajax( { "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback } ); } });
This is real time example.The aoData contains all the parameters which is required on server side and you can also push your own custom parameters