New to dataTables. how to I pass a value to server-side.php
New to dataTables. how to I pass a value to server-side.php
fkamwaza
Posts: 2Questions: 1Answers: 0
I need to change the "where-clause" in the sql statement that is used to fetch data from a db and display it in dataTables by changing the value of myInput and passing it on to the server-side. I have this code:
<input id=myInput value="london">
<script>
$(document).ready(function(){
$('#example').dataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "server_processing.php",
"data": function ( d ) {
d.myInput = $('#myInput').val();
}
}
});
} );
</script>
Server-side has this code:
<?php
//...HERE I have defined these: $sql_details, $table, $primaryKey, $columns
$myInput =$_POST['myInput'];
$where = " `office` = '$myInput' ";
require( 'ssp.class.php' );
echo json_encode(SSP::simple($_GET,$sql_details,$table,$primaryKey,$columns,$where));
How to I pass a value to server-side.php, this line is not being accepted: $myInput =$_POST['myInput'];
This discussion has been closed.
Answers
The request is being made as a GET request, but you are trying to read a POST variable. They need to match. Change one of them to match the other.
Allan
Thank for the pointer.
I have achieved what I needed with the following code. However I feel there might be a shortcut to this.