1

Possible Duplicate:
How does Stack Overflow notify of server-side events without a page reload? I see no request in Firebug

is there any way to alert the user so that they can perform a reload if there are changes on the page?

<script type="text/javascript">
     var page = 'data/apps/<? echo $_SESSION['name']; ?><? echo $_SESSION['last'];>App.html', lM;

function checkModified() {
   $.get(page, function(a, b, x) {
      var mod = (x.getResponseHeader('Last-Modified')) ? x.getResponseHeader('Last-Modified') : x.getResponseHeader('Content-Length');
      if (lM != mod) {
         lM = mod;
         console.log('Fetched');
         alert 
("Changes on "+<? echo $_SESSION['name']; ?><? echo $_SESSION['last']; ?>+"App.html has been made");
      }
   });
}

setInterval(checkModified, 5000); // every 5 seconds
</script>

both pages are located inside one domain.

Community
  • 1
  • 1
telexper
  • 2,381
  • 8
  • 37
  • 66
  • Stackoverflow does this when new answers are posted to questions while you are viewing them. Is this the functionality you are looking for? – Jared Oct 23 '12 at 02:53
  • YES!!! that's exactly what i'm looking for!! – telexper Oct 23 '12 at 02:54
  • WebSockets is the key. http://stackoverflow.com/questions/12425304/how-does-stack-overflow-notify-of-server-side-events-without-a-page-reload-i-se – Jared Oct 23 '12 at 02:55
  • SO.com even seems to use a fallback next to WebSockets. I am behind a proxy here and I get the notifications anyway. – Nippey Oct 23 '12 at 05:29

0 Answers0