<html>
<head>
  <script src='/javascripts/prototype.js'></script>
  <style>body {background:#444;color:#ccc;font-family:trebuchet ms;} strong {color:#fff}</style>
</head>
<body>
  <p><strong>Comet Messages:</strong></p>
  <div id='comet_target'></div>
  
  <script>
    var timestamp=0; // Remember the timestamp of the file that is being watched
    function comet_connect() // Start a comet request, this is where the magic happens
    {
      new Ajax.Request('/comet/comet_request', { // Here starts an ajax call; Comet is ajax in drag
        method:'get',
        parameters: {'timestamp':timestamp}, // Notify me when the file is newer than this
        onComplete: function(transport) { // If you will, this is the event handler or delegate
          var json = transport.responseText.evalJSON(); // Unpack the json response
          timestamp = json.timestamp; // Remember the new timestamp of the file
          $('comet_target').innerHTML += json.msg + '<br />'; // Display the response message
          setTimeout("comet_connect()",500); // Wait for the next event
        }
      });
    }
    comet_connect(); // Start the first comet request
  </script>
</body>
</html>class CometController @json end end
Thanks for reading! And if you want to get in touch, I'd love to hear from you: chris.hulbert at gmail.

(Comp Sci, Hons - UTS)
Software Developer (Freelancer / Contractor) in Australia.
I have worked at places such as Google, Cochlear, Assembly Payments, News Corp, Fox Sports, NineMSN, FetchTV, Coles, Woolworths, Trust Bank, and Westpac, among others. If you're looking for help developing an iOS app, drop me a line!
Get in touch:
    [email protected]
    github.com/chrishulbert
    linkedin