Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jscroll does not load the new content all the time #166

Open
munagurung opened this issue Jul 24, 2019 · 4 comments
Open

jscroll does not load the new content all the time #166

munagurung opened this issue Jul 24, 2019 · 4 comments
Assignees
Labels

Comments

@munagurung
Copy link

munagurung commented Jul 24, 2019

Hello,

I am using jscroll on a search page in a laravel app and it doesn't work all the time. Sometimes jscroll doesn't load the second page, I can see from the telescope that the jscroll has requested for the second page and that the app has returned a valid response. However, jscroll doesn't add the new content in the view and keeps on showing the loading html. I have attached an image of the developer tool's console log when the result does not load in the view.

jscroll

My jscroll js implementation looks like this.

window.addEventListener('load', initSearch);

function initSearch() {
    searchJScroll();
}

function searchJScroll() {
    const html = '<div class="text-muted align-items-center text-center"><i class="fas fa-2x fa-spinner fa-spin"></i> Loading...</div>';
    const options = {
        debug: true,
        autoTrigger: true,
        loadingHtml: html,
        padding: 0,
        nextSelector: '.pagination li.active + li a',
        contentSelector: '.jScroll',
        pagingSelector: '.pagination',
        callback: function () {
            $('ul.pagination').remove();
        }
    };

    $('.jScroll').jscroll(options);
}

Any insight would be greatly appreciated. Thanks.

@pklauzinski pklauzinski self-assigned this Jul 24, 2019
@pklauzinski
Copy link
Owner

Hi @munagurung - It is difficult to be sure without testing your code, but I suspect that because you are removing ul.pagination in your callback parameter, and that selector contains your nextSelector, then the nextSelector is not being found because it has been removed from the DOM.

Try calling $('ul.pagination').hide() instead of .remove() and see if that does the trick.

@munagurung
Copy link
Author

Hi @munagurung - It is difficult to be sure without testing your code, but I suspect that because you are removing ul.pagination in your callback parameter, and that selector contains your nextSelector, then the nextSelector is not being found because it has been removed from the DOM.

Try calling $('ul.pagination').hide() instead of .remove() and see if that does the trick.

Hey, thank you for your reply.

I have tried your suggestion but it is still not working. I am thinking that ul.pagination is not the problem because if it is, then the jscroll would output jScroll: nextSelector not found - destroying and the loading HTML would be removed. This does not happen in my case. Any other ideas?
It is very difficult to debug considering it does load the results sometimes but not all other times. :(

@wolfpack4417
Copy link

@munagurung I know this is an old post, but for anyone else who finds it later. Laravel has implemented Cursor Pagination which is more efficient for infinite scroll now. https://laravel.com/docs/8.x/pagination#cursor-pagination

If you're still having issues, let me know and I can try to help you debug them. I have infinite scrolling with Laravel's cursor pagination and jscroll working on my app with a complex query and the scroll occurring in an individual div on the page.

@ghost
Copy link

ghost commented Jan 13, 2022

@wolfpack4417
i have the same issue

<div class="infinite-scroll" >
// my for loop
@forelse ($posts  as $ite => $post)
...
@empty
@endforelse
{{ $posts->links() }}

</div>

.
.
.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jscroll/2.4.1/jquery.jscroll.min.js"></script>
<script type="text/javascript">
    $('ul.pagination').hide();
    $(function() {
        $('.infinite-scroll').jscroll({
            autoTrigger: true,
            loadingHtml: '<img class="center-block" src="logo/favicon.png" alt="Loading..." />',
            padding: 0,
            nextSelector: '.pagination li.active + li a',
            contentSelector: 'div.infinite-scroll',
            callback: function() {
                $('ul.pagination').remove();
            }
        });
    });
</script>

i am on laravel 8 and if i use cursorPaginate it will through an error :

BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::cursorPaginate()


Bad Method Call
Did you mean Illuminate\Database\Query\Builder::simplePaginate() ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants