javascript - ajax php jquery realtime saving of counter -
currently script.php works want happen, instead of displaying hours, minutes , seconds want have 3 values combined , posted log.php $_post['timespent'] value $id sent $_post['id'] every 1 second.
script.php
<p><span id="hours"></span>:<span id="minutes"></span>:<span id="seconds"></span></p> <script> var sec = -1; function pad(val) { return val > 9 ? val : "0" + val; } setinterval(function () { $("#seconds").html(pad(++sec % 60)); $("#minutes").html(pad(parseint(sec / 60, 10) % 60)); $("#hours").html(pad(parseint(sec / 3600, 10))); }, 1000); </script> log.php
<?php include 'includes/config.php'; $loggeduser = $_session['username']; $stmt = "update rotator_tracking set time_spent=:time_spent id=:id"; $stmt = $db->prepare($stmt); $stmt ->execute(array( ":time_spent" => $_post['timespent'], ":id" => $_post['id'] )); ?> i know variables need handed ajax hands them log.php in instance, have no idea how nor how save every 1 second.
help? perhaps example code.
in setinterval loop add
$.post( 'log.php', { timespent:thetimecombinedvariable, id:idvariable } ).done(function() { alert('done'); }); i did not test code. pretty it.
Comments
Post a Comment