kater Posted November 6, 2021 Share Posted November 6, 2021 I have visitors watching a stream and basically submit their attendance via a tracker. Click on button: "I'm here" -> create log-page. Click on button: "I'm out" -> add field value to this log-page. However, visitors are watching a stream or video an reloading the page would likely stop it and bloat other logs. For internal processing it would be nice to just have pw pages available rather than external logs/db. Is there a way to call pages api by js event? thanks! Link to comment Share on other sites More sharing options...
kongondo Posted November 6, 2021 Share Posted November 6, 2021 On 11/6/2021 at 2:49 PM, kater said: Is there a way to call pages api by js event? Yes. Using Ajax. There are many way to send an Ajax request to the server: vanilla JavaScript, jQuery (?), Axios, htmx ?...etc. A workflow like this maybe: Create buttons of type 'button' - to avoid them submitting the form normally. Choose the client-side library (or pure JS) that will to talk to the server. Listen to the click events on the buttons. I would probably toggle the buttons. User clicks on I am here: this sends an ajax request to your server. Create a session (or if you wanted, a cookie) to 'register' the user's presence. Populate your log-page. Send back a response to client, toggling the I am here button to a I am out button. This would be trivial if using htmx. User leaves: delete their session in #6. Amend your log-page. If stream still continuing, show I am here button. Stream ends: clear all sessions from #6. Something along those lines, assuming I understood your question ?. 3 Link to comment Share on other sites More sharing options...
kater Posted November 8, 2021 Author Share Posted November 8, 2021 Thanks kongondo! Pretty much did that but by populating the log file. I wasnt able to use the API from within the js (by just doing it) for following reason: in this install useFunctionsApi was disabled and $page() used. *facepalm* Just browsing htmx ... awesome. thanks for the hint! cheers Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now