javascript - Changing counter value after different time intervals using PhP, Ajax -
i want create counter changes value after different time interval. have written code dont know doing wrong. used ajax this, in different browser value changing randomly @ same time interval.
counter2.php
`$sql="select counter counter"; $result= mysql_query($sql); $rows=mysql_fetch_row($result); $counter=$rows[0]; //$counter--; echo $counter; $sql2="update counter set counter= counter-1"; $result2=mysql_query($sql2);
` ajax
countermain.php
<script type="text/javascript"> $(function() { var updateinterval = 1000; // 10 seconds, in milliseconds function updatecounter(){ $.ajax({ url: 'counter2.php', datatype: "json", type: "get", success: function(returnvalue){ $('#alpha').text(returnvalue); settimeout(updatecounter, 4000); } }); } setinterval(updatecounter, updateinterval); }); </script> </head> <body> <div id="alpha"></div>
let me know , doing wrong?
Comments
Post a Comment