I'm trying to use ajax to pass the time in seconds to the div with the div id of 'seconds', but for some reason it's not passing anything to the div. Please take a look at my code:
testing1.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript">
function timeoutAjax(url,id,timeout) {
$.ajax({
type: "POST",
url: url,
error: function(xhr,status,error){alert(error);},
success:function(data) {
document.getElementById( id ).innerHTML = data;
setTimeout(function() { timeoutAjax(url,id,timeout); }, timeout);
}
});
}
timeoutAjax("testing2.php","seconds",1000);
<div id = "seconds"></div>
</script>
testing2.php
<?php
$date = date("s");
echo $date;
?>
Put the div after closing script tag.
</script>
<div id = "seconds"></div>