sServerMethod: POST and overriding fnServerData do not work
sServerMethod: POST and overriding fnServerData do not work
ericDecker
Posts: 15Questions: 0Answers: 0
Hello,
I'm having trouble switching one of my Datatables from GET to POST. The table works in the default GET format, but as soon as I change it to use POST, the Datatable never gets populated, despite valid JSON being returned. I'm including a debug link, but unfortunately I cannot provide a test environment. I'm using the latest version of Datatables and I'm not getting any kind of error output in Firebug. Everything looks fine when I inspect the network traffic, so I'd really appreciate any advice that anyone could offer.
http://debug.datatables.net/atomop
I'm having trouble switching one of my Datatables from GET to POST. The table works in the default GET format, but as soon as I change it to use POST, the Datatable never gets populated, despite valid JSON being returned. I'm including a debug link, but unfortunately I cannot provide a test environment. I'm using the latest version of Datatables and I'm not getting any kind of error output in Firebug. Everything looks fine when I inspect the network traffic, so I'd really appreciate any advice that anyone could offer.
http://debug.datatables.net/atomop
This discussion has been closed.
Replies
Allan
Sorry for not being clear. I am testing the methods uniquely, but didn't think it would be worth posting a link to both versions.
Here is the code that I am trying to use in the function:
[code]"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}[/code]
I also tried it this way:
[code]"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": function(result){ fnCallback(result); }
} );
}[/code]
Both cases produce the same problem: the data is not being inserted to the Datatable. Am I not correctly setting it to post as you suggest?
Allan
Here is what my aoData reads:
[code][Object { name="sEcho", value=1}, Object { name="iColumns", value=20}, Object { name="sColumns", value=""}, Object { name="iDisplayStart", value=0}, Object { name="iDisplayLength", value=50}, Object { name="mDataProp_0", value="LEAD"}, Object { name="mDataProp_1", value="TYPE"}, Object { name="mDataProp_2", value="STATUS"}, Object { name="mDataProp_3", value="CHANGE_CONTROL"}, Object { name="mDataProp_4", value="APPLICATION_NAME"}, Object { name="mDataProp_5", value="QUESTION"}, Object { name="mDataProp_6", value="NOTIFICATION_DATE"}, Object { name="mDataProp_7", value="RESPONSE"}, Object { name="mDataProp_8", value="RESPONSE_SUBMIT_DATE"}, Object { name="mDataProp_9", value="RESPONSE_APPROVAL_DATE"}, Object { name="mDataProp_10", value="PROD_NAME"}, Object { name="mDataProp_11", value="ACTIVE_INGREDIENT"}, Object { name="mDataProp_12", value="STRENGTH"}, Object { name="mDataProp_13", value="FORM"}, Object { name="mDataProp_14", value="DOSSIER"}, Object { name="mDataProp_15", value="SECTION"}, Object { name="mDataProp_16", value="COUNTRY"}, Object { name="mDataProp_17", value="FILE_COUNT"}, Object { name="mDataProp_18", value="COMMENT_COUNT"}, Object { name="mDataProp_19", value="FOLLOWUP_COUNT"}, Object { name="sSearch", value=""}, Object { name="bRegex", value=false}, Object { name="sSearch_0", value=""}, Object { name="bRegex_0", value=false}, Object { name="bSearchable_0", value=true}, Object { name="sSearch_1", value=""}, Object { name="bRegex_1", value=false}, Object { name="bSearchable_1", value=true}, Object { name="sSearch_2", value=""}, Object { name="bRegex_2", value=false}, Object { name="bSearchable_2", value=true}, Object { name="sSearch_3", value=""}, Object { name="bRegex_3", value=false}, Object { name="bSearchable_3", value=true}, Object { name="sSearch_4", value=""}, Object { name="bRegex_4", value=false}, Object { name="bSearchable_4", value=true}, Object { name="sSearch_5", value=""}, Object { name="bRegex_5", value=false}, Object { name="bSearchable_5", value=true}, Object { name="sSearch_6", value=""}, Object { name="bRegex_6", value=false}, Object { name="bSearchable_6", value=true}, Object { name="sSearch_7", value=""}, Object { name="bRegex_7", value=false}, Object { name="bSearchable_7", value=true}, Object { name="sSearch_8", value=""}, Object { name="bRegex_8", value=false}, Object { name="bSearchable_8", value=true}, Object { name="sSearch_9", value=""}, Object { name="bRegex_9", value=false}, Object { name="bSearchable_9", value=true}, Object { name="sSearch_10", value=""}, Object { name="bRegex_10", value=false}, Object { name="bSearchable_10", value=true}, Object { name="sSearch_11", value=""}, Object { name="bRegex_11", value=false}, Object { name="bSearchable_11", value=true}, Object { name="sSearch_12", value=""}, Object { name="bRegex_12", value=false}, Object { name="bSearchable_12", value=true}, Object { name="sSearch_13", value=""}, Object { name="bRegex_13", value=false}, Object { name="bSearchable_13", value=true}, Object { name="sSearch_14", value=""}, Object { name="bRegex_14", value=false}, Object { name="bSearchable_14", value=true}, Object { name="sSearch_15", value=""}, Object { name="bRegex_15", value=false}, Object { name="bSearchable_15", value=true}, Object { name="sSearch_16", value=""}, Object { name="bRegex_16", value=false}, Object { name="bSearchable_16", value=true}, Object { name="sSearch_17", value=""}, Object { name="bRegex_17", value=false}, Object { name="bSearchable_17", value=true}, Object { name="sSearch_18", value=""}, Object { name="bRegex_18", value=false}, Object { name="bSearchable_18", value=true}, Object { name="sSearch_19", value=""}, Object { name="bRegex_19", value=false}, Object { name="bSearchable_19", value=true}, Object { name="iSortCol_0", value=6}, Object { name="sSortDir_0", value="desc"}, Object { name="iSortingCols", value=1}, Object { name="bSortable_0", value=true}, Object { name="bSortable_1", value=true}, Object { name="bSortable_2", value=true}, Object { name="bSortable_3", value=true}, Object { name="bSortable_4", value=true}, Object { name="bSortable_5", value=true}, Object { name="bSortable_6", value=true}, Object { name="bSortable_7", value=true}, Object { name="bSortable_8", value=true}, Object { name="bSortable_9", value=true}, Object { name="bSortable_10", value=true}, Object { name="bSortable_11", value=true}, Object { name="bSortable_12", value=true}, Object { name="bSortable_13", value=true}, Object { name="bSortable_14", value=true}, Object { name="bSortable_15", value=true}, Object { name="bSortable_16", value=true}, Object { name="bSortable_17", value=true}, Object { name="bSortable_18", value=true}, Object { name="bSortable_19", value=true}][/code]
> "sEcho": 0,
in your debug trace. It should never be 0. It will be 1 and then increment on every draw. That's probably the issue (without having a test case to see directly).
Allan
I'm running into trouble adding custom POST parameters to my request. I used the following code which I found in one of your old posts:
[code]aoData.push({'user_id':'<?php echo $_SESSION['project-name-userID']['userId'];?>','type':'<?php echo $TYPE;?>','ID':'<?php echo $ID;?>','session_id':'<?php echo $_SESSION['project-name-userID']['session_id'];?>'});[/code]
But when I inspect my parameters in the Firebug console, I only see the default Datatables parameters and one additional one named and valued "undefined." Can you please advise me on what I'm doing incorrectly?
Allan
[code]
aoData.push({ name: 'user_id', value: '<?php echo $_SESSION['project-name-userID']['userId'];?>' );
aoData.push({ name: 'type', value: '<?php echo $TYPE;?>' );
aoData.push({ name: 'ID', value: '<?php echo $ID;?>' );
aoData.push({ name: 'session_id', value: '<?php echo $_SESSION['project-name-userID']['session_id'];?>' );
[/code]
i.e. name value pairs like the example and documentation.
If that doesn't work, please link to a test case so I can debug it.
Allan