I'm doing a countdown Javascript, and I would like it when the count is == 0 , run a update in the database where it would go add a value
<script type="text/javascript">
var count=new Number();
var count=<?php echo $time ?>; //Valor da variável do banco de dados
function start(){
if ((count -1) >=0) {
count=count - 1;
if (count == 0)
{
// Quando count == 0 Adiciona(UPDATE) valor +10 dentro de uma variável do banco de dados
}
tempo.innerText=count;
setTimeout('start();', 1000);
}
}
</script>
EDIT ##
I am currently using this code and it is not working
HTML
<body onload="start();">
<div id="tempo"></div>
<form method="POST" action="insert.php" id="my_form">
<input type="text" name="id_user" value="ID_Que_Eu_Quero_Passar" style="display: none;">
<input type="text" name="id_view" value="ID_Que_Eu_Quero_Passar2" style="display: none;">
</form>
</body>
JQUERY AJAX
var count=new Number();
var count=10;
function start(){
if ((count -1) >=0) {
count=count - 1;
if (count == 0) {
$.ajax({
url: $(this).attr('insert.php')
,async: true
,cache: false
,type: $(this).attr('POST')
,data: $(this).serialize()
,dataType: 'json'
,success: function(data){
console.log("Update aconteceu");
if(data.success == 'yes'){
alert('Gol!');
}
else{
alert('insert failed!');
}
}
,error: function(){
}
,complete: function(){
}}); }
tempo.innerText=count;
setTimeout('start();', 1000);}}
PHP
<?php
echo $_POST['ID_Que_Eu_Quero_Passar'];
echo $_POST['ID_Que_Eu_Quero_Passar'];
?>