Jump to content

Periodic Refresh (First Week w/ Ajax)


alex4412

Recommended Posts

How would I make this refresh every say five seconds?

 

I found this but I'm not to sure how to implement this into the script... http://codeidol.com/ajax/ajaxdp/Browser-Server-Dialogue/Periodic-Refresh/

 

<html>
<head>
  <title>Boards 'R' Us</title>
  <link rel="stylesheet" type="text/css" href="boards.css" />
  <script type="text/javascript" src="text-utils.js"> </script>
  <script language="javascript" type="text/javascript">
   
   var request = null;

   function createRequest() {
     try {
       request = new XMLHttpRequest();
     } catch (trymicrosoft) {
       try {
         request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (othermicrosoft) {
         try {
           request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (failed) {
           request = null;
         }
       }
     }

     if (request == null)
       alert("Error creating request object!");
   }

  function getBoardsSold() {
   createRequest();
   var url = "boardSales.php";
   request.open("GET", url, true);
   request.onreadystatechange = updatePage;
   request.send(null);
  }
  
  function updatePage() {
   if (request.readyState == 4) {
    var newTotal = request.responseText;
    var boardsSoldEl = document.getElementById("boards-sold")
    var cashEl = document.getElementById("cash");
    replaceText(boardsSoldEl, newTotal);

var priceEl = document.getElementById("price");
      var price = getText(priceEl);
      var costEl = document.getElementById("cost");
      var cost = getText(costEl);
      var cashPerBoard = price - cost;
      var cash = cashPerBoard * newTotal;

    cash = Math.round(cash * 100) / 100;
    replaceText(cashEl, cash);
   }
}
  </script
</head>

<body>
  <h1>Boards 'R' Us :: Custom Boards Report</h1>
  <div id="boards">
   <table>
    <tr><th>Snowboards Sold</th>
     <td><span id="boards-sold">1012</span></td></tr>
    <tr><th>What I Sell 'em For</th>
     <td>$<span id="price">249.95</span></td></tr>
    <tr><th>What it Costs Me</th>
     <td>$<span id="cost">84.22</span></td></tr>
   </table>
   <h2>Cash for the Slopes: 
    $<span id="cash">167718.76</span></h2>
   <form method="GET">
    <input value="Show Me the Money" type="button"
     onClick="getBoardsSold();"/>
   </form>
  </div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/65128-periodic-refresh-first-week-w-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.