I am needing to automatically refresh my PHP page. I have a PHP page that is returning the current database time. However, this is requiring me to refresh the page in order for me to update.I need a better way of updating this PHP variable that does not include refreshing the page. Here's what I have so far:
$time = current_time($db);
echo '<p>$time</p>'
How can I accomplish this? EDIT: I've changed my code but it still won't auto-refresh: index.php
<div id="#timeLocation">
<script>
var updateTime = function(){
$.ajax({url: "time.php", success: function(response){
$('#timeLocation').html(response);
}});
setInterval(updateTime, 1000);
}
updateTime();
</script>
</div>
time.php
<?php
require_once('db.php');
require_once('functions.php');
$time = current_time($db);
echo $time[0];
?>