繁体   English   中英

PHP 未收到 ajax 发布数据

[英]PHP doesn't receive ajax post data

我已经为此苦苦挣扎了一周...我想在数据表中使用 Ajax 将一些参数传递给我的 PHP 文件以进行服务器端搜索。 但似乎我的 PHP 文件一无所获。 但是数据表工作得很好,该表可以从服务器端处理返回并正确显示在 html 页面上。 但是,var_dump($_POST['species']) 返回 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';

//如果我在这里尝试:$s=$_POST["s"]; echo $s;It //返回:警告:未定义的数组键“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.

尝试这个。 $_POST替换为$array

$array = json_decode(file_get_contents('php://input'), true); print_r($array);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM