I have a task to make web-page which shows server time (ajax) and have option to increment/decrement hours. It will be php+js. I have done next js:
$(document).ready(function() {
function update() {
$.ajax({
type: 'POST',
url: 'clocks.php',
timeout: 1000,
success: function(data) {
$("#clock_place").html(data);
window.setTimeout(update, 1000);
}
});
}
update();
});
And next php script:
<?php
$TIME = date('d/m/Y h:i:s');
switch($_POST["increment"]){
case "-":
$TIME=strtotime("-1 hour", strtotime($TIME));
echo date('d/m/Y h:i:s', $TIME);
break;
case "+":
$TIME=strtotime("+1 hour", strtotime($TIME));
echo date('d/m/Y h:i:s', $TIME);
break;
default:
echo $TIME;
}
?>
Well now I would like to hear buttons "+" and "-" onclick like this:
$("#send1").click(function(){
var param = {
increment: $("#send1").val(),
}
$.post("clocks.php", param);
});
$("#send2").click(function(){
var param = {
increment: $("#send2").val(),
}
$.post("clocks.php", param);
});
How can I do this? I tried, but I suppose that I can't interrupt js which renews time. Any advise!