I am trying to fetch pictures for a gallery using JavaScript, but I experience problems.
$(document).ready(function() {
var currentPage = 1;
var totalPics = 2;
var picPerPage = 1;
intervalID = window.setInterval(function() {
console.log(currentPage*picPerPage);
if (totalPics > (currentPage*picPerPage)) {
currentPage++;
fetchNextPage(currentPage);
} else {
clearInterval(intervalID);
}
}, 2000);
});
For some reason, it will keeping looping. I want it to stop the moment currentPage * picPerPage > totalPics
.
i am using firefox 3.6.8 in ubuntu
update
Thank you guys.
i realise that the issue is due to the fetchNextPage() function.
oncei commented it out, the looping issue is resolved.
however, i need the fetchNextPage function to run a ajax function to fetch another set of images.
below is the function
function fetchNextPage(currentPage) {
newUrl = currentUrl + currentPage;
$.ajax({
url: newUrl ,
success: function(data) {
// append page 2 themes
$('#themes-list').append(data);
}
});
}
so what should i do so that my infinite gallery can work?
Thank you.