2016-03-16 48 views
0

我打電話給ajax調用,但當我滾動2次其調用重複ajax調用..對於兩個滾動我得到重複ajax call.can任何人都可以幫助我如何糾正重複ajax調用。jQuery ajax無限滾動重複ajax調用

jQuery(function($){  
    $('#infscr-loading').hide(); 
    $(window).scroll(function() { //detect page scroll 
     if($(window).scrollTop() == $(document).height() - $(window).height()) { 
      var key = $(".tab-content div.active").attr("id"); 
      var offset = $(".tab-content div.active .movie_boot .movie-beta__item").length; 
      var data1 = $("#yr").val();    
      url = "/loop-movies/?offset="+offset+'&key='+key+'&yr='+data1; 
      $.ajax({ 
       type  : "post", 
       url  : url, 
       delay  : 500, 
       beforeSend : function(){ 
        $('#infscr-loading').show(); 
       }, 
       success : function(response) { 
        $(".tab-content div.active .movie_boot").append(response); 
        $('#infscr-loading').hide(); 
       } 
      });   
     } 
    }); 
}); 
+1

你寫Ajax調用,從而滾動 –

+0

我建議使用[無限的,它會調用多次](https://github.com/yairEO/infinite)或[無盡](https://github.com/yairEO/endless)易於使用的插件 – vsync

回答

1
var flag; 
if (flag.readyState == 4 && flag.status == 200) { 
    flag = $.ajax({ 
    type: "post", 
    url: url, 
    delay: 500, 
    beforeSend: function() { 
     $('#infscr-loading').show(); 
    }, 
    success: function(response) { 
     $(".tab-content div.active .movie_boot").append(response); 
     $('#infscr-loading').hide(); 
    } 
    }); 
} 
else{ 
    alert("AJAX is going on") 
} 

Demo Fiddle顯示在窗口的滾動工作

Reference

+0

此標誌拯救了我的生命。謝謝!!! –

+0

@GabrielBenamy ......哈哈......總是很高興聽到':)' –