I have been struggling with it for a week...I want to use Ajax in datatables to pass some parameters to my PHP file for server side searching. But it seems my PHP file got nothing. But the datatable works just fine and the table can return from sever side processing and display on the html page correctly. However, var_dump( $_POST['species']) returns null.
$(document).ready(function() {
console.log(species);
$("#table").DataTable({
"destroy": true,
"serverSide": true,
"processing": true,
"paging": false,
"searching": false,
columns: [{
data: "d"
},
{
data: "c"
},
{
data: "p"
}
],
ajax: {
type: "POST",
data: {
"species": s
},
url: "./php/search_test.php"
}
});
});
<div class="container text-center" id="tablecontainer" name="tablecontainer">
<table id="table" class="display nowrap row-border strip p-2" cellspacing="0" width="100%">
<thead class="thead-dark">
<tr>
<th>
<center>d</center>
</th>
<th>
<center>C</center>
</th>
<th>
<center>P</center>
</th>
</tr>
</thead>
</table>
</div>
'''php
ini_set ('memory_limit', '2048M');
$sql_details = array(
'host' => 'localhost',
'user' => 'root',
'pass' => '',
'db' => 'xxxxx'
);
// DB table to use
$table = 'h';
//if I try this here: $s=$_POST["s"]; echo $s;It //returns: Warning: Undefined array key "s".
// Table's primary key
$primaryKey = 'd';
// column
$columns = array(
array( 'db' => 'd', 'dt' => 'd' ),
array( 'db' => 'c', 'dt' => 'c' ),
array( 'db' => 'p', 'dt' => 'p' ),
);
// Include SQL query processing class
require( 'ssp.class.php' );
echo json_encode(
SSP::complex( $_POST, $sql_details, $table, $primaryKey,$columns)
);
Could someone help me with it? Thanks.
specieseven is (no declaration at all), it's hard to tell what you're doing wrong - it's also interesting to note that the PHP you posted make no reference tospeciesanyway, so, not sure what you think anyone could do for you with the absolute lack of information regarding your so called issuespeciesdeclared before you try to use it in{"species":species}?Share Edit Close Delete)