I have this code:
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
var site_url = $("#site_url").val();
var post_url = site_url+"index.php/ajax/get_more_users";
$("#loading_more_users").show();
var users_page = $("#users_page").val();
//alert("y");
$.post(post_url, {'page': users_page}, function(data){
//alert("x");
$("#loading_more_users").hide();
$("#left_members_collumn").append(data);
$("#users_page").val(eval(Number(users_page)+1));
});
}
});
Anyone can tell me why the $.post are executed once, twice or three times when I scroll bottom? I get the duplicate content. The main function is executed fine, but I don’t know why there are multiples ajax requests.
Thank you.
The scroll is firing multiple times with criteria that satisfy your if condition. What you can do to prevent this is set a bool to indicate your are posting, so you don’t post twice: