我有一个困扰我的问题。我有一个发送 json 对象的 ajax 函数,我看到在 F12 Chrome 标头中解析了 JSON,我收到了成功警报。
$(document).ready(function() {
var test = {'bob':'foo','paul':'dog'};
$.ajax({
url: "test.php",
type: 'POST',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(test),
success: function(data) {
alert("Bien: " + data);
},
failure: function(errMsg) {
alert("Mal: " + errMsg);
}
});
});
Run Code Online (Sandbox Code Playgroud)
但是在我的 PHP 页面中,我看不到任何 POST,任何东西。我可以看到我的帖子已收到,但还有其他内容:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "post"; //Result 'post'
}
foreach( $_POST as $stuff ) {
echo $stuff; //Nothing at all
}
print_r(json_decode($_POST["data"], true)); // Undefined index: data
Run Code Online (Sandbox Code Playgroud)
在我使用的相同代码中
$.post( "test.php", { …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
$dateInt = intval($date);
$stmt = $this->db->prepare('SELECT * FROM establecimientos WHERE timestamp > ?');
$stmt->bindParam($dateInt);
$stmt->execute();
Run Code Online (Sandbox Code Playgroud)
而且我收到了这个错误:
调用未定义的方法mysqli_stmt :: bindParam()
我确定有一些非常错误,但我当然不知道!