2017-12-21 7 views
1

私はjquery/ajaxでページ区切りのようなシステムを作ろうとします。私がバトンビューを押すと、さらに次の5つの結果が表示されますjquery/ajaxのページ区切りのようなもの

<button class="btn" id="showFiveNext">View more</button> 

私はこのことをどうやって知っていますか?私の最初の方法でオフセットした新しい節LIMITをajaxに設定することは可能でしょうか、またはshow/hide somes要素の計算を計算する必要がありますか?

は、私は私の要素聖霊降臨祭この方法

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; 
    } 
} 

を取得し、私はこの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){ 

      } 
     }); 
    } 

とカウンターwhith結果を示す

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; 
    } 
} 

この方法whithカウント

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){ 

      } 
     }); 
    } 

ご協力いただきありがとうございました。

答えて

0

私はそれを得ると思います。私は関数getCountComment()whith value = 5に隠し入力を追加します。

「もっと見る」ボタンをクリックすると、この入力の値が得られ、私はajaxリクエストを開始し、LIMIT句はこの入力の値。

このリクエストが成功した場合、私は入力の値に '5'を追加します。

私はボタンの上に私のLIMITをクリックするたびに5

そのが働いていたが、その良い方法がわからない取ります。