2017-10-17 39 views
0

後保存價值我有這個功能後,我跑點擊按鈕如何每次點擊與阿賈克斯

function Wo_GetMorePosts() { 

    var query = $(".search-for-posts").val() 

    if (search_status == "1"){ 

     Wo_SearchForPosts(query,1) 

    }else{ 
     $.get(Wo_Ajax_Requests_File(), { 
      f: 'posts', 
      s: 'load_more_posts', 
      filter_by_more: filter_by_more, 
      after_post_id: after_post_id, 
      user_id: user_id, 
      page_id: page_id, 
      group_id: group_id, 
      posts_count: posts_count 
     }, function (data) { 
      if (data.length == 0) { 
       $.get(Wo_Ajax_Requests_File(), {f: 'get_no_posts_name'}, function (data3) { 
        $('#load-more-posts').html('<div class="white-loading list-group"><div class="cs-loader"><div class="no-more-posts-to-show">' + data3.name + '</div></div>'); 
       }); 
      } else { 
       $('#posts').append(data); 
      } 
     }); 

    } 
    $('#load-more-posts').show(); 
    $('.loading-status').remove(); 
    Wo_progressIconLoader($('#load-more-posts')); 
    scrolled = 0; 
} 

我的問題是在Wo_SearchForPosts(query,1)我希望每一個點擊後增加了第二個參數(數量)。所以第二次點擊將是Wo_SearchForPosts(query,2)

我該怎麼做呢?

+1

在'Wo_GetMorePosts()'函數上面添加一個變量'var counter = 1;'。將'Wo_SearchForPosts(query,1);'替換爲'Wo_SearchForPosts(query,counter ++);' – Patrick2607

回答

0

創建一個全局變量計數器,然後增加一個計數器。

var counter = 0; 
    function Wo_GetMorePosts() { 

     var query = $(".search-for-posts").val() 

     if (search_status == "1"){ 
      Wo_SearchForPosts(query,++counter) 
     }else{ 
      $.get(Wo_Ajax_Requests_File(), { 
       f: 'posts', 
       s: 'load_more_posts', 
       filter_by_more: filter_by_more, 
       after_post_id: after_post_id, 
       user_id: user_id, 
       page_id: page_id, 
       group_id: group_id, 
       posts_count: posts_count 
      }, function (data) { 
       if (data.length == 0) { 
        $.get(Wo_Ajax_Requests_File(), {f: 'get_no_posts_name'}, function (data3) { 
         $('#load-more-posts').html('<div class="white-loading list-group"><div class="cs-loader"><div class="no-more-posts-to-show">' + data3.name + '</div></div>'); 
        }); 
       } else { 
        $('#posts').append(data); 
       } 
      }); 
     } 
     $('#load-more-posts').show(); 
     $('.loading-status').remove(); 
     Wo_progressIconLoader($('#load-more-posts')); 
     scrolled = 0; 
    }