我有两个文件,一个 JavaScript 文件和一个 PHP 文件。
在 JS 文件中,我正在运行 POST 请求。
$.ajax({
type: "POST",
url: 'http://localhost/tracker/functions.php',
dataType: 'text',
data: {
name: "John Doe",
age: "19"
},
success: function (obj, textstatus) {
console.log(textstatus);
},
error: function (xhr, status, error) {
console.log(xhr, status, error);
}
});
我只是在 php 文件中打印 $_POST
<?php
print_r($_POST);
?>
它只打印一个空数组
最佳答案
从我的 PHP 脚本中获取 JSON 数据,我通常这样做
echo file_get_contents('php://input');
所以也许你可以在你的 php 文件中做
<?php
print_r(file_get_contents('php://input'));
?>
关于javascript - JQUERY AJAX $_POST 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47778172/