User Tools

Site Tools


tutorials:zencartmods:daily_ajax.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:zencartmods:daily_ajax.html [2011/06/22 16:11]
daigo
tutorials:zencartmods:daily_ajax.html [2016/01/28 18:05] (current)
Line 1: Line 1:
 ==== AJAXify your Daily stats ==== ==== AJAXify your Daily stats ====
 +
 +{{:​tutorials:​zencartmods:​dailystats.gif|}}
  
 Last week, we created a [[daily_stats.html| daily stats]] page. If you're like us, then you compulsively click refresh on this page way too often! So lets AJAX-ify this page so that it updates automatically every time someone makes an order. Last week, we created a [[daily_stats.html| daily stats]] page. If you're like us, then you compulsively click refresh on this page way too often! So lets AJAX-ify this page so that it updates automatically every time someone makes an order.
Line 11: Line 13:
  
 If you're hosting it on your own server, then add into the **<​head>​** section of daily_stats.php If you're hosting it on your own server, then add into the **<​head>​** section of daily_stats.php
-<​code>​+<​code ​html>
 <script src="​https://​you.path/​to.jquery.js"></​script>​ <script src="​https://​you.path/​to.jquery.js"></​script>​
 </​code>​ </​code>​
  
 or if you're using a CDN (this one is Google) then use or if you're using a CDN (this one is Google) then use
-<​code>​+<​code ​html>
 <script type="​text/​javascript"​ src="​https://​www.google.com/​jsapi?​key=YOUR_API_KEY"></​script>​ <script type="​text/​javascript"​ src="​https://​www.google.com/​jsapi?​key=YOUR_API_KEY"></​script>​
 <script src="​https://​ajax.googleapis.com/​ajax/​libs/​jquery/​1.6.1/​jquery.min.js"></​script>​ <script src="​https://​ajax.googleapis.com/​ajax/​libs/​jquery/​1.6.1/​jquery.min.js"></​script>​
Line 27: Line 29:
 At the top of **daily_stats.php**,​ add this code AFTER the **require('​includes/​application_top.php'​);​** At the top of **daily_stats.php**,​ add this code AFTER the **require('​includes/​application_top.php'​);​**
  
-<​code>​+<​code ​php>
 $action = $_POST['​action'​];​ $action = $_POST['​action'​];​
  
Line 53: Line 55:
  
 This will make daily_stats.php echo out 2 different JSON files, depending on post data. '​latest'​ will be used for polling (we can poll the server every 5, 10, 15 seconds or so) and '​stats'​ will be triggered by new information in the polling event. ​ This will make daily_stats.php echo out 2 different JSON files, depending on post data. '​latest'​ will be used for polling (we can poll the server every 5, 10, 15 seconds or so) and '​stats'​ will be triggered by new information in the polling event. ​
 +
 +There'​s and **exit()** after it returns the data so that if we jsut want the JSON data, it wont continue rendering the page or anything.  ​
  
 === Client Side Javascript === === Client Side Javascript ===
/home/ladyada/public_html/wiki/data/attic/tutorials/zencartmods/daily_ajax.html.1308759117.txt.gz · Last modified: 2016/01/28 18:05 (external edit)