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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.