【发布时间】:2018-06-04 12:15:07
【问题描述】:
我尝试在 jquery/ajax 中制作类似分页的系统。当我按下按钮视图时,我会显示 5 个下一个结果
<button class="btn" id="showFiveNext">View more</button>
但我不知道该怎么做。可以在我的第一个方法中在 ajax 中设置一个新的子句 LIMIT 偏移量,或者我必须对显示/隐藏某些元素的计数器进行计算?
我通过这个方法得到了我的元素
function getVideoComment($idVideo)
{
$q = $this->db->select('*')->from('users_youtube_videos_comment uyvc')
->join('users_youtube_videos uyv', 'uyv.users_youtube_videos_id = uyvc.users_youtube_videos_id', 'left')
->join('users u', 'u.users_id_nat = uyv.users_youtube_videos_id_user', 'left')
->join('users_profils up', 'up.users_profils_id = u.users_id_nat', 'left')
->order_by('uyvc.users_youtube_videos_comment_id', 'DESC')
->limit('5')
->where('uyvc.users_youtube_videos_id', $idVideo)
->get();
if($q->num_rows()>0)
{
foreach($q->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
我也算这个方法
function getCountComment($idVideo)
{
$q = $this->db->select('count(users_youtube_videos_comment.users_youtube_videos_comment_id) AS commentCount')
->from('users_youtube_videos_comment')
->where('users_youtube_videos_comment.users_youtube_videos_id', $idVideo)
->get();
if($q->num_rows()>0)
{
foreach($q->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
我通过这个 ajax 请求显示结果
function getComment(){
var videoId = '<?php echo $idVideo ?>';
jQuery.ajax({
type: "GET",
url: "<?php echo base_url(); ?>video/getVideoComment?videoid=" +videoId,
dataType: 'json',
success: function(resGetVideoCom){
$('#showVideoComm').empty();
$.each(resGetVideoCom,function(key, value){
var avatarUser = '<img class="img-circle" src=" '+value.users_youtube_avatar_channel+' " height="52" alt="avatar user" >';
var pseudoUser = '<span class="pseudoComment">'+value.users_youtube_pseudo_channel+'</span>';
var commentDate = '<span class="dateComment"> '+value.users_youtube_videos_comment_date+'</span><br>';
var commentValue = '<div class="valueComment">'+value.users_youtube_videos_comment_com+'</div><br><br>';
$('#showVideoComm').append(
avatarUser+
pseudoUser+
commentDate+
commentValue
);
});
},
error:function(resGetVideoCom){
}
});
}
和柜台
function getCountComment(){
var videoId = '<?php echo $idVideo ?>';
jQuery.ajax({
type: "GET",
url: "<?php echo base_url(); ?>video/getCountComment?videoid=" +videoId,
dataType: 'json',
success: function(resGetCountComment){
$('#showCountVideoComm').empty();
$.each(resGetCountComment,function(key, value){
var counterCom = '<span>'+value.commentCount+' commentaires</span>';
$('#showCountVideoComm').append(
counterCom
).hide().fadeIn("slow");
});
},
error:function(resGetCountComment){
}
});
}
感谢您的帮助,对不起我的英语。
【问题讨论】:
标签: jquery ajax codeigniter pagination