我尝试在jQuery/ajax中制作类似Systeme。当我推动Boutton视图时,我将显示5个下一个结果
<button class="btn" id="showFiveNext">View more</button>
,但我不知道该怎么办。可以在Ajax中设置一个新的子句限制在我的第一个方法中的抵消,或者我必须制作一个计算器作为显示/隐藏somes元素的计数器?
我得到我的元素whit这个方法
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){
}
});
}
感谢您的帮助,很抱歉我的英语。
我认为我明白了。我在函数getCountComment()whith value = 5。
中添加了一个隐藏的输入。当我单击"查看更多"按钮时,我将获得此输入的值,然后启动一个ajax请求,限制子句是此输入的值。
关于此请求的成功,我在输入的值中添加了" 5"。
每次我单击按钮时,我的限制 5
它有效,但不确定它的好方法。