如何使用 JSON 从 while 循环中打印数据?
目前,我在message.php
<script type="text/javascript">
$('#pmid<?php echo $convoData['id']; ?>').click(function(){
$.ajax({
type:"GET",
url: "/index.php?i=pm&p=rr",
dataType:'json',
data: {id:"<?php echo $convoData['id']; ?>"},
success : function(res){
if(res){
$( "#name").html(res.name);
$( "#post").html(res.response);
}
}
});
});
</script>
<span id="name"></span>
<ul id="post">
</ul>
在get.php
文件中,我有这个:
$name=$getUser['username'];
while($postData=mysql_fetch_assoc($postsql)){
$post = '<li>
<img width="30" height="30" src="images/avatar-male.jpg">
<div class="bubble">
<a class="user-name" href="">123</a>
<p class="message">
'.$postData['text'].'
</p>
<p class="time">
</p>
</div>
</li>';
}
$arrRet = array();
$arrRet['name'] = $name;
$arrRet['post'] = $post;
echo json_encode($arrRet);
die();
到目前为止, $name 值是有效的。我可以把它打印出来#name
。我只是不知道如何打印出 $post while 循环#post