[英]Can't send content of Javascript Console Log to PHP?
我有一個程序,應該將JSON從控制台發送到PHP
var nice = any_jsonfile;
console.log(JSON.stringify(nice)); // here it shows desired contents
var nice2 = JSON.stringify(nice);
$.ajax({
type: "POST",
url: "/postgetter.php",
data: nice2,
dataType: "text"
});
Postgetter包含
<?php
$data = $_POST;
$data_string=implode ( $data );
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = $data_string;
echo "<pre>";
print_r($data);
echo "</pre>";
fwrite($myfile, $txt);
fclose($myfile);
?>
我看到ajax正在發送它,但沒有任何數據輸入到postgetter.php中
我在這里做錯了什么?
嘗試使用:
$data = file_get_contents("php://input");
參見https://stackoverflow.com/a/12997460/2460773
有時$ _POST全局將為空,具體取決於發送的數據類型。 在這種情況下,您可以使用file_get_contents來獲取原始POST數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.