【问题标题】:Pagination-like in jquery/ajaxjquery/ajax 中的分页
【发布时间】: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


    【解决方案1】:

    我想我明白了。我在我的函数 getCountComment() 中添加了一个隐藏输入,其值 = 5。

    当我点击“查看更多”按钮时,我会得到这个输入的值并启动一个 ajax 请求,LIMIT 子句就是这个输入的值。

    在此请求成功后,我在输入值中添加“5”。

    每次我点击按钮时,我的 LIMIT 都会 +5

    它的工作,但不确定它的好方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-18
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      • 2012-12-21
      • 1970-01-01
      • 2016-08-19
      相关资源
      最近更新 更多