Jump to content

Use AJAX to get field content


louisstephens
 Share

Recommended Posts

I have been wanting to set up a quick "dashboard" for a recent project, and was considering using ajax to get a "real time" update/refresh on the page (some of my output depends on the datetime field). I know how to get the desired output using php with some if statements comparing todays date to the date stored in the field, however, I am a bit at a lose of how to interact with the ProcessWire API using ajax to get the desired effect. I found the following 

 

and know that I need to start off with: 

<?php
if($config->ajax) {
    // page was requested from ajax
}

Unfortunately, as I mentioned earlier, how would one actual find pages using a template and get the field contents from them using AJAX? I apologize if this seems bit broad, but I am stil getting a grasp of using AJAX to deliver content to get a real time update on a page without refresh.

Link to comment
Share on other sites

AJAX or normal request doesn't really matter to backend. You just detect if request is an AJAX request and act accordingly.

Because I had some things to do, I decided to procrastinate by building a simple module and write a tutorial for it.

 

  • Like 4
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...