Posting additional data to a php-file - I am not succeeding in doing that.
Posting additional data to a php-file - I am not succeeding in doing that.
AndersBranderud
Posts: 4Questions: 0Answers: 0
Hello!
I would like to post some additional data to a php-file using Datatables.
I try to do this below; however, I check the data inside of the php-file and it isn't posted.
What is wrong with the following code?
Thanks!!
[code]
var oTable;
var gaiSelected = [];
var init =0;
var pathAdminDataPhp ="bachelors/adminShowData.php";
$(document).ready(function() {
oTable = $('#usersTable').dataTable( { //Send request to adminShowData.php
"bProcessing": true,
"bRetrieve": true,
"bServerSide": true,
"sAjaxSource": pathAdminDataPhp,
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "mode": "initialMode", "checkBoxes":"none" } );
$.getJSON( pathAdminDataPhp, aoData, function (json) {
fnCallback(json)
} );
} //end of fnServerData
}); //end of datatable.
(...)
[/code]
Thanks!
Anders Branderud
fly.to/truth
I would like to post some additional data to a php-file using Datatables.
I try to do this below; however, I check the data inside of the php-file and it isn't posted.
What is wrong with the following code?
Thanks!!
[code]
var oTable;
var gaiSelected = [];
var init =0;
var pathAdminDataPhp ="bachelors/adminShowData.php";
$(document).ready(function() {
oTable = $('#usersTable').dataTable( { //Send request to adminShowData.php
"bProcessing": true,
"bRetrieve": true,
"bServerSide": true,
"sAjaxSource": pathAdminDataPhp,
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "mode": "initialMode", "checkBoxes":"none" } );
$.getJSON( pathAdminDataPhp, aoData, function (json) {
fnCallback(json)
} );
} //end of fnServerData
}); //end of datatable.
(...)
[/code]
Thanks!
Anders Branderud
fly.to/truth
This discussion has been closed.
Replies
I edited my code slightly. It still isn't working.
I have tried to follow the guidance in the example of the example page, but it still isn't working.
[code]
var oTable;
var gaiSelected = [];
var init =0;
var pathAdminDataPhp ="bachelors/adminShowData.php";
//Do this at start up!
$(document).ready(function() {
oTable = $('#usersTable').dataTable( { //Send request to adminShowData.php
"bProcessing": true,
"bRetrieve": true,
"bServerSide": true,
"sAjaxSource": pathAdminDataPhp,
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "mode": "initialMode",
"checkBoxes": "none" } ); //push to aoData..
$.ajax({
"type": "POST",
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"url": sSource,
"data": aoData,
"success": fnCallback
});
} //fnServerData
}); //end of datatable.
[/code]
Thanks in advance!
Anders Branderud
fly.to/truth
[code]
aoData.push( { "mode": "initialMode", "checkBoxes": "none" } );
[/code]
to:
[code]
aoData.push( { "key": "mode", "value": "initialMode" }, { "key": "checkBoxes", "value": "none" } );
[/code]
Allan
The data is posted. However, I don't know how to access the data in the php-file. I have tried to do it in several ways, e.g. by doing $_GET['mode'], but with no success.
My current code on the client side: [code]
$(document).ready(function() {
$('#usersTable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": pathAdminDataPhp,
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "key": "mode", "value": "initialMode" },
{ "key": "checkBoxes", "value": "none" } );
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
alert ("test");
fnCallback(json)
} );
}
} ); //end of datatable. [/code]
Cheers, Anders Branderud
} ); [/code //end of ready..