ajax
$.ajax({
type : "get",
async: true,
url : url,
dataType : "json",
success : function(data){
if(data == 1){
$('#more').html('没有更多评论!').unbind('click');
return false;
}
$.each(data,function(i,element){
var nickname = element.nickname;
var content = element.content;
var time = element.time;
var imgpath = element.imgpath;
var info = $('<li class="comment"><div class="left"><img src="'+imgpath+'"></div><div class="right"><div>'+nickname+'</div><div></div>'+content+'</div></li><hr>');
$('#contentList').append(info);
});
var now = parseInt($('#last').val()) + 2;
$('#last').val(now);
},
error:function(){
console.log('fail');
}
});
php页面
$query=mysql_query("select * from comment order by id desc limit $last,$amount");
$flag = false;
while ($row=mysql_fetch_array($query)) {
$flag = true;
$sayList[] = array(
'id'=>$row['id'],
'nickname'=>$row['nickname'],
'content'=>$row['content'],
'imgpath'=>$row['imgpath'],
'time'=>$row['time']
);
}
if($flag){
echo json_encode($sayList);
}else{
echo true;
}