我正在使用 ajax 发送这个数组
代码jQuery:
$("#btnReact").on("click", function (e) {
var post = {};
post["comment"] = $("#bug_message").val();
post["id"] = $(this).data("bid");
var request = $.ajax({
url: "ajax/save_comment.php",
type: "POST",
data: {
post: post
},
dataType: "json"
});
request.done(function (msg) {
if(msg.status == "success") {
}
});
request.fail(function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
e.preventDefault();
});
但是我无法在 php 中访问我的数据,并且当我尝试将这些数据发送到我的班级时,我不断收到错误消息。
代码 php:
if(isset($_POST["post"]))
{
try
{
$comment = $_POST['post']["comment"];
$id = $_POST['post']["id"];
$comment = new Comment();
$comment->Comment = $comment;
$comment->SaveComment($id);
$feedback['status'] = "success";
}
catch(Exception $e)
{
$feedback['message'] = $e->getMessage();
$feedback['status'] = "error";
}
header('Content-Type: application/json');
echo json_encode($feedback);
}
我的语法有问题还是其他问题?