I wrote a simple script where I am using ajax $.get to get my data for infinite scrolling. The problem is, I am maybe scrolling faster than it is loading, causing it to load three times?
function last_msg_funtion()
{
var ID=$(".feed_container").last().attr("id");
$.ajax({
url: "ajax/pagination.php",
type:"get",
data: "p="+ID
}).done(function(data){
if (data != "")
{
var $boxes = $(data);
//$(".feed_container:last").after(data);
$("#feed_main").append($boxes).masonry('appended',$boxes);
}
});
$(window).scroll(function(){
var mostOfTheWayDown = ($(document).height() - $(window).height()) - 300;
if ($(window).scrollTop() >= mostOfTheWayDown)
{
//alert('test');
last_msg_funtion();
}
}
If I scroll all the way down, it takes a while to load. The data I'm returning in last_msg_function() is the AJAX $.get() where I'm getting images. However, it is loading triple the same data. Any idea to prevent this?
Thanks