亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取所有數據后使加載更多按鈕消失

獲取所有數據后使加載更多按鈕消失

PHP
阿波羅的戰車 2023-05-26 09:27:59
我的代碼工作正常,單擊加載更多按鈕時它會顯示更多用戶。我現在的限制是如果響應沒有更多價值,如何刪除加載更多按鈕。這就是我的模型的樣子 public function getFreeAds($page){        $offset = 10*$page;        $limit = 10;        $this->db->select('*');        $this->db->from('escort');        $this->db->where('status', 'Approved');        $this->db->limit($offset ,$limit);        $this->db->order_by("time_stamp, UPPER(time_stamp)", "DESC");        $query = $this->db->get();        return $query->result();    }我的控制器看起來像這樣 public function getCountry(){        $page =  $_GET['page'];        $countries = $this->Home_model->getCountry($page);        foreach($countries as $country){            echo                  '<div class="col-md-4 col-sm-6">                    <div class="portfolio-item">                     <div class="thumb">                    <a ><div class="hover-effect" data-e_id="'.$country->e_id.'" id="profile2">                    <div class="hover-content">                    <h1> '.$country->ProfileName.'</em></h1>                     <p> '.$country->Height.' CM tall '.$country->BreastCup.'  Breast Size <b>Nationality: '.$country->Nationality.' </b></p>                     <button  type="button"  class="btn-info">View More</button>                     <button  type="button"  class="'.$country->confirmstatus.'">'.$country->confirmstatus.'</button>                     <div class="top">                     </div>                     </div>                     </div></a>                     <div class="image" width="70%" height="1000px">                     <img src="uploads/'.$country->ProfilePicture.'">                     </div>                     </div>                     </div>                    </div>';        }        exit;    }這是我顯示響應的查詢代碼。$(document).ready(function(){        getcountry(0);        $("#load_more").click(function(e){            e.preventDefault();            var page = $(this).data('val');            getcountry(page);        });    });
查看完整描述

2 回答

?
吃雞游戲

TA貢獻1829條經驗 獲得超7個贊

你可以做的是在同一個函數中獲取下一個值,如果有可用的值,你可以創建一個輸入字段(隱藏),然后根據它的值顯示或隱藏按鈕。


我正在為您的案例編寫一個可能的解決方案,必要時會提到評論。請記住,有更好的方法可以做到這一點,例如使用計數,但這是根據您的代碼??纯此欠駥δ阌袔椭?。


控制器


public function getCountry(){


        $page       =  $_GET['page'];

        $countries  = $this->Home_model->getCountry($page);


        $nextValue  = $this->Home_model->getCountry($page+1); // get the values for the next page

        $showButton = !empty($nextValue) ? 'yes' : 'no'; // show the button if next value exists


        foreach($countries as $country){

            echo 

                 '<div class="col-md-4 col-sm-6">

                    <div class="portfolio-item">

                     <div class="thumb">

                    <a ><div class="hover-effect" data-e_id="'.$country->e_id.'" id="profile2">

                    <div class="hover-content">

                    <h1> '.$country->ProfileName.'</em></h1>

                     <p> '.$country->Height.' CM tall '.$country->BreastCup.'  Breast Size <b>Nationality: '.$country->Nationality.' </b></p>


                     <input type="hidden" class="showButton" value="'.$showButton.'" /> 

                     <!-- make a hidden input field and assign a value (yes/no) -->


                     <button  type="button"  class="btn-info">View More</button>

                     <button  type="button"  class="'.$country->confirmstatus.'">'.$country->confirmstatus.'</button>

                     <div class="top">

                     </div>

                     </div>

                     </div></a>

                     <div class="image" width="70%" height="1000px">

                     <img src="uploads/'.$country->ProfilePicture.'">

                     </div>

                     </div>

                     </div>

                    </div>';

        }

        exit;

    }

看法


var getcountry = function(page){

    $("#loader").show();

    $.ajax({

        url:"<?php echo base_url() ?>Home/getCountry",

        type:'GET',

        data: {page:page}

    }).done(function(response){

        $("#show_data").append(response);

        $("#loader").hide();

        $('#load_more').data('val', ($('#load_more').data('val')+1));


        // check the value of input field

        if($('.showButton:last').val() == "no"){


            $('#load_more').hide(); // hide the button

        }


        scroll();

    });

};


查看完整回答
反對 回復 2023-05-26
?
米脂

TA貢獻1836條經驗 獲得超3個贊

使用總頁數添加到您的響應元數據。在每個請求期間,使用相同的子句對您的數據庫進行計數查詢。在每次請求后的 JS 代碼中,將當前頁面與響應中的總頁數進行比較,如果到達最后一頁,則隱藏按鈕。



查看完整回答
反對 回復 2023-05-26
  • 2 回答
  • 0 關注
  • 150 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號