weixin_33681778 2017-11-25 06:00 采纳率: 0%
浏览 26

已加载的发布按钮禁用

how do we disable the button when all posts are loaded ?

all post loaded = button disabled or hide

or show another way ajax load more pagination codeigniter :(

I know little english sorry

Controller

public function getCountry(){
  $page =  $_GET['page'];
  $this->load->model('posts_model');
  $posts = $this->posts_model->getCountry($page);
  foreach($posts as $post){
     echo "<h3>".$post->post_title."</h3><td>".$post->post_content."</td>";
  }
  exit;
}

Model

public function getCountry($page){
    $offset = 2*$page;
    $limit = 2;
    $sql = "select * from posts limit $offset ,$limit";
    $result = $this->db->query($sql)->result();
    return $result;
}

Script

<script>
    $(document).ready(function(){
      getcountry(0);
      $("#load_more").click(function(e){
        e.preventDefault();
        var page = $(this).data('val');
        getcountry(page);
      });
    });

    var getcountry = function(page){
      $("#loader").show();
      $.ajax({
        url:"<?php echo base_url() ?>welcome/getCountry",
        type:'GET',
        data: {page:page}
      }).done(function(response){
        $("#ajax_table").append(response);
        $("#loader").hide();
        $('#load_more').data('val', ($('#load_more').data('val')+1));
        scroll();
      });
    };
    var scroll  = function(){
      $('html, body').animate({
        scrollTop: $('#load_more').offset().top
      }, 1000);
    };
</script>
  • 写回答

1条回答 默认 最新

  • 撒拉嘿哟木头 2017-11-25 06:30
    关注

    In your get country function you can do like this. so whenever you get the empty results it means no more result available and your button will be disabled.

    <script>
    
        var getcountry = function(page){
          $("#loader").show();
          $.ajax({
            url:"<?php echo base_url() ?>welcome/getCountry",
            type:'GET',
            dateType:'json', 
            data: {page:page}
          }).done(function(response){
            if(response.result == 'success') {
               $("#ajax_table").append(response.data);
               $("#loader").hide();
               $('#load_more').data('val', ($('#load_more').data('val')+1));
               scroll();
            } else {
               $("#load_more").prop('disabled',true);
            }
          });
        };
    </script>
    

    In your controller make this changes

    public function getCountry(){
      $page =  $_GET['page'];
      $this->load->model('posts_model');
      $posts = $this->posts_model->getCountry($page);
      $response = array();
      $data = '';
      if(!empty($posts)) {
        foreach($posts as $post){
          $data .= "<h3>".$post->post_title."</h3><td>".$post->post_content."
                </td>";
        } 
        $response = array('result'=>'success','data'=>$data); 
      } else {
         $response = array('result'=>'error');
      }
      echo json_encode($response)
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码求涡量
  • ¥100 采用栈和深度优先算法对我的代码进行修改显示路径
  • ¥15 pointnet2包安装
  • ¥20 射频功率问题,解答者有酬谢!
  • ¥80 构建降雨和积水的预测模型
  • ¥15 #Qt Transform setTransform()在鼠标拖动移动视角是一致在原地不动,无法变换视角(细微观察似乎视图有在原地抖动),无法变换视角(细微观察似乎视图有在原地抖动)
  • ¥50 如何利用无人机拍摄的数码照片测量鸟卵的长短径
  • ¥100 github贡献者给与奖励
  • ¥15 使用DS18B20+ESP8266获取温度数据返回-127.00
  • ¥15 odbc代码新增sqlserver数据源