我有一个 AJAX 请求,它本质上是查询数据库,然后将数据发布回 JS,但是我无法打印单个数据位。
我的代码如下:
$.ajax({
type: 'POST',
url: '_process/offerrespres.php',
dataType: 'json',
data: {
msgid: msgid,
usrid: usrid
},
success: function(){
console.log(JSON.parse(data.pro_name));
console.log(data.accept_decline);
}
});
PHP:
<?php
include_once 'connect.php';
if ($_POST) {
$msgid = mysql_escape_string($_POST['msgid']);
$usrid = mysql_escape_string($_POST['usrid']);
$getmsgq = mysql_query("SELECT * FROM booking_requests WHERE receiver_id = '$usrid' AND msg_id = '$msgid'");
$getmsg_info = mysql_fetch_array($getmsgq);
$data['success'] = true;
$data['date_sent'] = $getmsg_info['date_sent'];
$data['pro_name'] = $getmsg_info['pro_name'];
$data['accept_decline'] = $getmsg_info['accept_decline'];
}
header("Content-Type: application/json", true);
echo json_encode($data);
mysql_close();
?>
如您所见,我已经尝试过:
console.log(JSON.parse(data.pro_name));
console.log(data.accept_decline);
控制台中的错误显示“未定义数据”。PHP文件的输出是正确的,应该是正确的,我只是无法打印一条数据。