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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置