簡體   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