How to use Ajax source, with parameters and an SQL request
How to use Ajax source, with parameters and an SQL request
CharlyPoppins
Posts: 16Questions: 2Answers: 0
Hi,
i've got something like [code]var oTable = $('#liste_documents').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "script_affichedossier.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );[/code]
In script_affichedossier.php I'm getting such as 10000 records if my SQL request has no parameters.
How can I get parameters "aoData" given by DataTables ? I didn't manage to "trace" them.
Is that the good way to use DataTables and Ajax ?
i've got something like [code]var oTable = $('#liste_documents').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "script_affichedossier.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );[/code]
In script_affichedossier.php I'm getting such as 10000 records if my SQL request has no parameters.
How can I get parameters "aoData" given by DataTables ? I didn't manage to "trace" them.
Is that the good way to use DataTables and Ajax ?
This discussion has been closed.
Replies
I think there might be a way you can add parameters to your sAjaxSource (simply concatenate them, since it's a string) and if your ajax source is a PHP script you can honor the params you add. you'd want to modify sAjaxSource for each call (if the params change). I suspect you can do this with the oSettings.
[code]
// make sure "script_affichedossier.php" can accept the params you send and form your JSON appropriately
var oTable = $('#liste_documents').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "script_affichedossier.php?" + params,
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
[/code]
as your params change, this MIGHT work (test, because i'm not sure. also not sure the best place to put this code.. just somewhere before a DRAW is called)
[code]
oTable.fnSettings().sAjaxSource = "script_affichedossier.php?" + newparams;
[/code]
Je vais repartir à zéro et je verrais bien.
En tout cas merci pour la réponse :)