How do I pass a parameter to a server script?
How do I pass a parameter to a server script?
ostmal
Posts: 102Questions: 33Answers: 0
Pass the parameter from the JS script according to the documentation like this (https://editor.datatables.net/reference/option/ajax.data):
ajax: {
url: 'php/staff.php',
data: {
"user_id": 451
}
},
Sorry, but I didn't find how to accept it on the server. I do this:
$user_id = $_POST['user_id'];
DataTables swears, how is it correct?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I do this:
JavaScript:
PHP:
The script does not output the table and writes: «DataTables warning: table id=dt_08 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1»
Strange, like I'm doing everything right, like here:
https://datatables.net/blog/2016-03-25#Server-side-(PHP)
But, If I set a value:
The script is running.
DataTables sends a GET request by default so either:
or if you are mixing with Editor, which does a POST by default, use:
in the
ajax
option for the DataTable.Allan
I don't use PHP but I think $_POST is to retrieve the parameters from a POST request. You have set the Ajax request type to POST so it is sending the request as a GET. In this case I think you will need to use $_GET.
Kevin
Thank you very much! Really appreciate it!