stateSaveCallback / stateLoadCallback with PHP
stateSaveCallback / stateLoadCallback with PHP
Hello,
I am trying to save the state of a datatable in a session via PHP but sadly I have do not have any success. Maybe someone can give me a helping hand.
Here the snippet from datatable:
"stateSaveCallback": function (settings, data)
{ // Send an Ajax request to the server with the state object
$.ajax(
{
"url": "state_save.php",
"data": data,
"dataType": "json",
"method": "POST"
} );
}
Here the code of state_save.php (For testing, I just write it to a textfile):
$fp = fopen("test.txt","w");
fwrite($fp,var_dump($_POST));
fclose($fp);
The file is created, but it is empty.
When debugging the javascript, the variable "data" is filled with all values but it seems I am doing something wrong in the php part. Obviously reading from POST is not enough.
Since I was not able to find an example of a php code (maybe I was just blind), I would like to ask if someone is able to help me.
Thanks in adavance!
Dragon013
This question has an accepted answers - jump to answer
Answers
In jQuery I think you want to use:
At the moment it is probably sending as a GET, which you can confirm with your browser's developer tools.
Allan
Hello Allan,
I just tried
and now I was able to read the needed values. Thanks a lot!
One question about method vs. type, in the example at https://datatables.net/reference/option/stateSaveCallback there is "method" used. What's the difference to "type" ?
Thanks!
Dragon013
That's a bug in the documentation! Sorry about that! I've committed the fix and will deploy it to this site soon.
Allan