2013-01-15 68 views
0

嗨有沒有任何參考/示例的PHP AJAX選項卡加載更多的功能在每個標籤?可以說我們有2個選項卡,當我們點擊每個選項卡時,它將只顯示選定的結果數量,直到我們在每個結果的末尾點擊加載更多按鈕。謝謝。我當前的代碼似乎沒有工作得很好,當我點擊每個選項卡它顯示正確結果,但是當我再次單擊該選項卡,它加載更多data.Below是我當前的代碼:Jquery製表符加載更多按鈕

<li data-tab-id="self" class="tab selected"><a href="#">Near You</a><span class="unread-count hidden" style="display: none;"></span></li> 


<li data-section-id="user_feed" data-component-bound="true"> 
    <ul class="module-list">        
    <!-- USER ACTIVITY JSON --> 
    </ul> 
    <a class="ybtn ybtn-primary ybtn-large more-wishlist" href="#" onclick="getRecentActivityClick(event)"> 
    <span data-component-bound="true" class="loading-msg user_feed">See more recent activity</span> 
    </a> 
</li> 

<script type="text/javascript"> 
var totalRecords = '<?= $this->totalRecords?>'; 
$(document).ready(function(){ 
getRecentActivity(totalRecords); 
}); 

$(".hd-ui-activity li a").click(function(e) { 
e.preventDefault(); 
var tabid = $(this).parent().attr('data-tab-id'); 
if(tabid == "self"){ 
     getRecentActivity(totalRecords); 

    } 
}); 

function getRecentActivityClick(event) 
{ 
    if (event != null){ 
      disabledEventPreventDefault(event); 
     } 
     getRecentActivity(totalRecords); 
} 

home.js:

function getRecentActivity(totalRecords) 
{ 
$.ajax({ 
     url:baseUrl + "activity/activityfeed", 
     data:{'total':totalRecordsView}, 
     dataType:"json", 
     type:"POST", 
     success:function(data){ 

var activityHtml = '<p>Hello</p>'; 
$('#activity-feed li[data-section-id=near_you] .module-list').append(activityHtml); 


} 
}); 

} 

UPDATE: 的jsfiddle:http://jsfiddle.net/zlippr/5YkWw/1/

回答

0

與我從你的問題理解..我覺得你越來越DATAS因爲u的採用.. append() .. 使用html()

append()將由參數指定的內容插入匹配元素集中每個元素的末尾。

html()用於設置元素的內容,該元素中的任何內容都被新內容完全替換。

試試這個

更換

$('#activity-feed li[data-section-id=near_you] .module-list').append(activityHtml); 

$('#activity-feed li[data-section-id=near_you] .module-list').html(activityHtml); //html() 
+0

仍然沒有得到解決,當我點擊標籤仍然加載新的數據,它不應該加載,直到用戶點擊加載更多的按鈕數據底部.. –

+0

它不清楚你在哪裏得到...你正在加載內容在$(document).ready(function(){...'..這就是爲什麼你得到的adata之前點擊..你可以創建這個小提琴嗎? – bipen

+0

k完成http://jsfiddle.net/zlippr/5YkWw/1/ –

0

你可以這樣做:

$('#activity-feed li[data-section-id=near_you] .module-list').append(activityHtml); 
// here you are appending the fulldata just apply some css here 

我們ËCSS是這樣的:

$('#activity-feed li[data-section-id=near_you] .module-list') 
    .css({'height':'300px','overflow':'hidden'}) 
    .append(activityHtml); 

然後單擊loadmore:

$('your load more button').toggle(function(){ 
    $('#activity-feed li[data-section-id=near_you] .module-list') 
    .css({'height':'auto','overflow':'auto'}) 
    },function(){ 
    $('#activity-feed li[data-section-id=near_you] .module-list') 
    .css({'height':'300px','overflow':'hidden'}); 
});