The code below generates json data dynamically from the database. When the data is generated it adds it to a specific div. How can i make the contents of JSONObject reload every 30 seconds. This will make it so that content shows changes in near real-time.
<script>
JSONObject = <?php echo include_once('../includes/dashboard-stats.php'); ?>;
document.getElementById("today_visits").innerHTML=JSONObject.todayVisits;
</script>
Below is the output of JSONObject = <?php echo include_once('../includes/dashboard-stats.php'); ?>;
JSONObject = {"todayEarnings":"2.60","todayVisits":"212","todayClicks":"36","todayLeads":"3","todayCalculateCR":"12%","todayEPC":"0.08","todayCTR":"17%","yesterdayEarnings":"0.40","yesterdayClicks":"35","yesterdayVisits":"148","yesterdayLeads":"1","yesterdayCalculateCR":"35%","yesterdayEPC":"0.03","yesterdayCTR":"24%","monthEarnings":"3.00","monthClicks":"75","monthVisits":"392","monthLeads":"4","monthCalculateCR":"19%","monthEPC":"0.05","monthCTR":"19%"}
1;
I tried using this to try and reload the json data.
<script>
function load(){
JSONObject = <?php echo include_once('../includes/dashboard-stats.php'); ?>
document.getElementById("today_visits").innerHTML=JSONObject.todayVisits;
setTimeout("load()",9000);
}
</script>
jquery? If you use jquery, check out its ajax functions.