JQuery and PHP Infinite Scrolling Help
I'm having a problem with my infinite scrolling. As I scroll down, it loads the next items fine but it keeps sending those items. I've been using this jquery to give it a unique id because I have ordered the items with mysql with an algorithm:
$("#image-list li").each(function(index) {
$(this).attr('id', index);
});
and inorder to label the newly given items from an external php file, I have to use this code in the file as well.
To send the information about the items given, I've been using this jquery:
function last_db_item_function()
{
var ID=$(".db-item:last").attr("id");
$('div#last-db-item-loader').html('<img src="loading.gif" height="30px" />');
$.post("index.php?action=get&last_db_item="+ID,
function(data){
if (data != "") {
$(".db-item:last").after(data);
}
$('div#last-db-item-loader').empty();
});
};
$(window).scroll(function(){
if ($(window).scrollTop() == $(docu开发者_高级运维ment).height() - $(window).height()){
last_db_item_function();
}
});
but the problem is that it does not seem to work. Which I mean it doesn't not gather that last item id from the newly parsed php file. To parse the php I've been doing this:
$last_db_item = $_GET['last_db_item'];
$action = $_GET['action'];
if($action != "get")
{
.... Code Here....
}else{
include ('secondimages.php');
}
So my question is, why does this seem to go on forever?
It looks like you're never assigning a new ID to the new elements when you append them to the list. The first snippet you have either needs to be called after every new element is added, or similar code needs to be applied to that one element when you add it (unless it's coming back in the php, at which point we'd need to know more about what you're returning)
精彩评论