pklauzinski / jscroll

An infinite scrolling plugin for jQuery.
http://jscroll.com/
1.11k stars 563 forks source link

Unable to reinitialize after ajax #27

Closed versello closed 8 years ago

versello commented 10 years ago

Having an issue where jscroll doesn't bind after ajax load. I've read "Problem with dynamic content #11" which sounds like my issues, but cannot find a resolution. jscroll doesn't seem to want to find after being destroyed.

$('#search').on('input propertychange', function() {
    $.ajax({
        url: 'list.php?query=' + $('#search').val(),
        success: function(data){
            $('#file-container').jscroll.destroy();
            $('#file-container').html(data);
            $('#file-container').jscroll({
                debug: true,
                nextSelector: '.more',
                autoTrigger: false,
                loadingHtml: '<div id="processing"></div>'
            });
        }
    });
});
versello commented 10 years ago

I seemed to have found a fix to my problem.

Commented out line 206: if (data && data.initialized) return;

allucardster commented 10 years ago

I have the same problem, however I agree with the solution exposed by @lauth on #11. I mean, just use the method "removeData" before execute destroy method:

$('.your_selector').removeData('jscroll').jscroll.destroy();

This has the same effect exposed by @versello without modify the plugin code.

snow-walker commented 10 years ago

Thanks @allucardster , fixed my issue with ajax search.

efriandika commented 9 years ago

i have same problem with you. i just add:

$('#selector').removeData('jscroll');

it solved my problem.