我已成功从 mysql 接收数据,代码如下
alert(data);
$.each(data, function(index, data) {
alert(index);
alert(data);
});
我想看看data.comments。警报(数据)中的消息是
[{"visible":"0","comments":"fiat","post_id":"103007636522630"},{"visible":"0","comments":"volvo","post_id":"103007636522630 "}]
但是,在 each 函数中,它会显示每个字符,例如 index=1, data=[, index=2, data={, index=3, data=">
有谁知道为什么会发生这种情况,我想获取整行而不是每个字符
PHP 代码
$data2= $_POST['string'];
$data3= explode(",", $data2);
$data = array();
foreach ($data3 as &$value) {
$sql = "SELECT * FROM afb_comments where post_id='".$value."'";
$result = mysql_query($sql,$conn);
while($row = mysql_fetch_array($result)){
$row_data = array(
'visible' => $row[0],
'comments' => $row[1],
'post_id' => $row[2]
);
array_push($data, $row_data);
}
}
echo json_encode($data);