Jump to content

Using Ajax requests with hidden pages


terry
 Share

Recommended Posts

Pretty new to processwire and really enjoying it so far. I'm trying to build a pretty simple Ajax driven website (pretty new to me so excuse my general ignorance regarding ajax) which inserts content from child pages into a parent page. I've read through Ryan's thread here which was super helpful, but still can't quite figure out the best practices for what I'm trying to achieve.

For now, all I'm trying to do is have the parent page load content from a child page with an ajax request, BUT these child pages also need to be inaccessible via the URL processwire creates for them.

So the child pages are hidden via their template's access options. The /parent/ page successfully loads some initial content from these child pages using the "include=all" selector ( $pages->get("/parent/")->children('include=all'); ) as recommended in this thread. However as the child pages are hidden any ajax request to pull data from them results in a 404.

If anyone can suggest the best practices for using processwire to create a site like this it would be a huge help. I assume that later I may have issues with linking/indexing by using this approach, but am happy to figure those out later.

Link to comment
Share on other sites

An ajax request needs an URL by nature, so for doing this you will have to have them available via URL. You can however throw a 404 if they are not requested via a post.

if(!$input->post->secret) throw new Wire404Exception();

for this, you would have to use a method that sends some post info to the server via JS.

  • Like 1
Link to comment
Share on other sites

Hey diogo, thanks for suggesting that. The child page template is now unhidden so ajax calls can be made, but throws a 404 if it wasn't requested via ajax. Like this:

if($config->ajax) { content } else { throw new Wire404Exception(); }
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...