I currently have this code in place to update a codebox on the page with data retrieved from dyntask.php.
<script type="text/javascript">
if(typeof(EventSource)!=="undefined") {
var eSource = new EventSource("dyntasks.php");
eSource.onmessage = function(event, previous) {
document.getElementById("serverData").innerHTML = event.data;
};
}
</script>
The data fetched from dyntask.php is sourced from a text file containing updates like:
2018-05-10 14:02:01: starting task 99333
2018-05-10 14:02:03: task 99333 completed
2018-04-13 15:13:44: triggered tasks
2018-05-10 14:05:52: starting task 99334
2018-05-10 14:05:57: task 99334 completed
2018-05-10 14:11:01: starting hidden task 99335
2018-05-10 14:11:07: hidden task 99335 completed
updating...
The last line of the text file always reads "updating...". The requirement is to constantly monitor the second to last line for changes:
- The monitoring should commence whenever the keyword "starting" appears in a line
- Once that keyword is detected, the script should then search for the occurrence of the word "completed"
- If "completed" is found, the script should trigger a full page refresh
My JavaScript knowledge is limited to what was necessary to create this script. I am hopeful that someone proficient in JavaScript can add just TWO lines to make it work as intended.
Could you please offer some guidance?