POST vs sAjaxSource":
POST vs sAjaxSource":
jimbooth97
Posts: 5Questions: 0Answers: 0
I have gotten DataTables to work perfectly when I used sAjaxSource as what I needed was a database dump into the tables. But now i need to search for certain criteria that is dynamically driven by the user. In the past I used POST to send the data to search the database on (before using DataTables). The below javascript works good for the database dump, is there an easy way to pass along a few variables to only return certain information? I apologize in advance.. as this is a bit new to me.
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bPaginate": true,
"bProcessing": true,
"bAutoWidth": false,
"bServerSide": true,
"bSortable_3": false,
"sAjaxSource": "tripsgps.php"
} );
} );
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bPaginate": true,
"bProcessing": true,
"bAutoWidth": false,
"bServerSide": true,
"bSortable_3": false,
"sAjaxSource": "tripsgps.php"
} );
} );
This discussion has been closed.
Replies
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "more_data", "value": "my_value" } );
}
} );
} );
Allan
$.ajaxSetup( {'type': 'POST', 'url':'tripsgps.php', 'dataType': 'json' } );
var oPostData = {'user':username, 'vehicle':uservehicle, 'regnumber':userregnumber};
//oPostData['name3'] = this.options.value3;
$('#example').datatable({
'sAjaxSource': $.ajaxSettings.url,
'aoAjaxData':oPostData
});
All you need to do is add `sServerMethod: 'POST'` to the DataTables initialisation:
http://datatables.net/release-datatables/examples/server_side/post.html
Allan
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/post.php", data: {hognum:hognum, vehicle:vehicle},
"sServerMethod": "POST"
} );
} );
Allan