Reputation: 229
We can use datatable plugin request data from server like this:
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../server_side/scripts/server_processing.php"
} );
We write the server url as "sAjaxSource": "../server_side/scripts/server_processing.php". but if I want custom the request just ues a asynchronous function just like this:
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"requestFunction": function(params, callback){
callback([....]);
}
} );
how can I do this?
Upvotes: 0
Views: 777
Reputation: 14419
Try using: fnServerData
This parameter allows you to override the default function which obtains the data from the server ($.getJSON
) so something more suitable for your application. For example you could use POST data, or pull information from a Gears or AIR database.
$(document).ready( function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "xhr.php",
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
} );
Upvotes: 1