0

So I am using jQuery waypoint to get the image id that is viewed on the screen. But I am having problem with content added by AJAX. When I get to the newly added content by AJAX the plugin doesn't work. Here is my code so far:

Waypoint = $('.Picture-1A').waypoint(function(direction){
    if(direction == 'down'){
        id = $(this.element).children(".PictureID").text();
        $.post('ajax/count-pictures-views.php', {picture_id: id}, function(data){
            Waypoint.refreshAll();
        });
    }
});

I have also tried this instead of Waypoint which did not work. What can I do to make this work?

3
Contributors
8
Replies
33
Views
1 Year
Discussion Span
Last Post by FarrisFahad
0

I haven't heard of waypoint til now but my first thought would be that elements added after waypoint is initialised don't get included because they weren't part of the DOM at that time.
Is the new content getting added after the page has finished loaded i.e. by user action, or is everthing loaded by the time the document is ready?
It could just be that your waypoint initialisation needs to be the very last thing to occur.

0

It works with content that is already on the page but when ever I load new content it doesn't work on the new content.

0

In that case I would say is almost certainly because waypoint scans the DOM at page load only. Items added after that don't get found. Finding out how you can force waypoint to go over the DOM again after those new items are added would solve your problem.

0

Add it to the $post request. Something like this

$.post('ajax/count-pictures-views.php', {picture_id: id}, function(data)).done(function() {
    Waypoint.refreshAll();
})
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.