Search code examples
phpajaxcodeigniterjplayer

Compare database value to current value and submit via AJAX


I have a web application using codigniter that sends users to a jPlayer playlist after they submit some info on a form.

My client has asked me to retrofit it to record the time watched for each video in the playlist.

I have this working on click. When a track is clicked, an ajax function is called, then the controller checks the time value against whatever is already in the database, and if the current value is larger, it is submitted.

What I would like to do is remove the click functionality so that if the time watched for any of the videos becomes greater than the value in the database, the AJAX submit is automatically called. Any suggestions for a strategy on this? Should my AJAX query write a session variable for each of the time values in the database and then be triggered based on that?


Solution

  • Create an object that holds the video ID/name and the time values. You will then extract the corresponding video time value and set that as a variable. Using setInterval() refresh every X seconds, comparing the set time value and the elapsed time. If the threshold is exceeded, then perform the AJAX submission.