Detect ajaxPager event

Hy

I use ajaxPager for pagination and i want to go to the top of the page after after moving from one page to another page.
I tested with document.addEventListener(‘ajax:done’,… but it not working.

Any idea ?

Thanks

Hi @ridha82,

Your idea using “ajax:done” makes sense! When you say it’s not working, what do you mean exactly?

Hi @apinard

i did this

 addEventListener('ajax:promise', function(event) {
      console.log('ajax:promise');
    });
    addEventListener('ajax:done', function(event) {
      console.log('ajax:done');
    });

‘ajax:promise’ is executed but not ‘ajax:done’

Thanks

Does ajax:success work?

hy @daft

no, only ajax:promise work.

Thanks

@ridha82 so then, maybe the ajax request is failing? what is the http code of the response in the Network tab? if you do something like this:

addEventListener('ajax:fail', function(event) {
    console.log('ajax:fail', event);
});

do you see something?

Hi @apinard

ajax:fail is not called. I don’t think the query failed, because the pagination works well, I go from page 1 to page 2 without problem.

This is how i call the partial “{% ajaxPartial ‘products/list’ %}” and this is how i call the pager inside the partial “{{ ajaxPager(products) }}”

Thanks

There is a difference between document.addEventListener and window.addEventListener. The documentation outlines which element it is called on, and sometimes the events don’t bubble (blocked by another script)