ajax seems to work only in page:2 but on page:3 it loads the page:3 page. I find it very weird.
heres my controller
return function($site, $pages, $page) {
$Numberoftags = $page->number_of_popular_tags()->int();
$perpage = $page->perpage()->int();
$articles = $page->children()
->visible()->filterBy('date', '<=', time())->sortBy('date', 'desc')
->paginate($perpage);
$tagcloud = tagcloud(page('blog'), array('limit' => $Numberoftags));
$isarticles = $page->children()->visible()->filterBy('date', '<=', time());
$isfeatured = $isarticles->flip()->first();
$pagination = $articles->pagination();
$tagcloud = $tagcloud;
if(kirby()->request()->ajax()){
// in ajax request - this snippet will be returned by the server.. the site and page object should be redeclared in here...
// in ajax, the global objects are unknown
exit(snippet('blog/blog-area', compact('articles','tag', 'perpage', 'pagination','tagcloud'), true));
} else {
return compact('articles','tag', 'perpage', 'pagination','tagcloud');
}
};
One problem here is that the pagination buttons are loaded in the snippet. So the jQuery in your footer knows nothing of what to make it that and the third page is not loaded via XHR but as a normal link. To prevent that behavior, you’d have to bind the event to an element, rather than just using the normal click event.