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

TA貢獻1836條經驗 獲得超3個贊
使用總頁數添加到您的響應元數據。在每個請求期間,使用相同的子句對您的數據庫進行計數查詢。在每次請求后的 JS 代碼中,將當前頁面與響應中的總頁數進行比較,如果到達最后一頁,則隱藏按鈕。
- 2 回答
- 0 關注
- 150 瀏覽
添加回答
舉報