Jaxel
Well-known member
In previous versions of XF, I had page navigation handled through AJAX. This way I could navigate through pages of comments, without reloading the page, just the comment pane:
This worked great. Not only would it load the next page, but it would also re-register any future page navigation links that were loaded in that next page.
However, in XF2.3, I'm having trouble with this. I am able to successfully get it to AJAX load a page. However, it doesn't register any page navigation links in the next page. So after the first page swap, the AJAX no longer functions.
How would I register new elements loaded in the new page?
Code:
init: function()
{
this.$target.on('click', '.pageNavWrapper a', $.proxy(this, 'click'));
},
click: function(e)
{
e.preventDefault();
if ($(e.currentTarget).attr('href'))
{
const wrapper = this.$target;
XF.ajax('get', $(e.currentTarget).attr('href'), {}, function(data)
{
if (data.html)
{
XF.setupHtmlInsert(data.html, wrapper);
}
});
}
},
However, in XF2.3, I'm having trouble with this. I am able to successfully get it to AJAX load a page. However, it doesn't register any page navigation links in the next page. So after the first page swap, the AJAX no longer functions.
Code:
init: function()
{
this.target.querySelectorAll('.pageNavWrapper a').forEach(element =>
{
XF.on(element, 'click', this.click.bind(this));
});
},
click: function(e)
{
e.preventDefault();
if (e.target.href)
{
const wrapper = this.target;
XF.ajax('GET', e.target.href, {}, function(data)
{
if (data.html)
{
XF.setupHtmlInsert(data.html, (html, container) =>
{
wrapper.innerHTML = html.innerHTML;
})
}
});
}
},