javascript - How to Reload JSONObject Content -
The code below dynamically generates JSON data from the database. When the data is generated then it adds to a specific device. How can I reload the contents of JSONObject every 30 seconds, so that the content shows changes in near-real-time.
& lt; Script & gt; JSONObject = & lt ;? Php echo include_once ('../ included / dashboard-stats.php'); ? & Gt ;; Document.getElementById ("today_visits") innerHTML = JSONObject.todayVisits. & Lt; / Script & gt; below JSONObject = & lt ;? The output of Php echo include_once is ('../ contains / dashboard-stats.php'); "Today": "212", "todayclix": "36", "nowadays": "nowadays": "3", "todayCalculateCR": "12%", "todayEPC": "0.08", "todayCTR": " "", "YesterdayEarnings": "0.40", "yesterdayClicks": "35", "yesterdayVisits": "148", "yesterdayLeads": "1", "yesterdayCalculateCR": "35%", "yesterdayEPC": " "Month", "month", "month", "month,": "3.00", "monthClicks": "75", "month visits": "392", "month leads": "4", "monthly calculator ":" 19% "," monthPC ":" 0.05 "," month CTR ":" 19% "} 1; I tried and tried to use it to reload Jason data.
& lt; Script & gt; Function Load () {JSONObject = & lt ;? Php echo include_once ('../ included / dashboard-stats.php'); ? & Gt; Document.getElementById ("today_visits") innerHTML = JSONObject.todayVisits. SetTimeout ("Load ()", 9000); } & Lt; / Script & gt;
Renewed Comment: & lt; Script & gt; Function load () {var color = ["#CCCCCC", "# 333333", "# 990099"]; Var Rand = Math Floor (monastery. Rhythm () * colors.length); $ .getJSON ("../ included / dashboard-statistics.pph", {get: "stats"}, function (data) {$ ("# today_visits"). FadeOut (.) FadeIn () .html (data today Visits). CSS ("background color", color [rand]);); } $ (Function () {load (); // on page load. SetInterval (load, 9000);}); & Lt; / Script & gt; The URL is relative to the location of the page on which the script exists
Comments
Post a Comment