Thread tagged as: Problem, Blog

Ajax content and pagination

Hi all

Not sure if this is a problem in Perch or a problem with my approach.

Problem 1 I have two types of blog post that can be filtered using an ajax call, the initial ajax request makes a call to a script called "get-posts.php" and works fine, i.e it returns the correct number of posts filtered appropriately and it has pagination links at the bottom.

So my blog url would be https://<mysite>/blog/

and my paginated links for normal posts would be https://<mysite>/blog/?p=2

The problem occurs when you click on the pagination links after filtering via Ajax, when you click on the any page link, whether that be a numbered page or next page etc the URL now looks like this


So it using the ajax script as it's source page, so the blog posts (or content) load but they have no template as this script is only meant for returning the relevant content back to the original page, if that makes sense.

Problem 2 After noticing this problem I went back to an old Perch site and noticed an issue with ajax and paginated content. The initial Ajax PHP script being called was a file name ajaxJobSearch (camel case) however the paginated links using perch:content ID of next_url behaves in the same way as above but instead ajaxJobSearch.php it has the url as ajaxjobsearch (lower case) resulting in page not found. I changed this all to lowercase and it works but has the same issue as above i.e it returns a list of unstyled results because it doesn't exist in a page template.

<perch:if exists="not_last_page">
        <a href="<perch:content id="next_url" type="hidden" encode="false" />">Next</a>

I hope this makes sense. Can you have paginated ajax results, and if so is the problem I am experiencing a Perch thing or do I need to change my approach?

Lee Goodman

Lee Goodman 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

When Perch constructs the next_url it is with the current URL as the basis. If you need to return something different, perhaps construct it yourself in the template using the next_page_number value instead.

Perch lowercases page paths for complex and boring reasons that aren't worth worrying about other than to know that you should use lowercase.

Great Thanks Drew.