繁体   English   中英

无法将Javascript控制台日志的内容发送到PHP?

[英]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.

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