Search code examples
jqueryajaxeventslivemonitor

Monitor server events and update list in web page


In a list of events I present on a web page I want to offer the feature to get "live" updates in case of an event on the server side. So kind of a live monitor instead of reloading the list in a polling cycle.

I guess I need something like this:

- Client: open a socket to the server (ajax like), 
          listening for events, 
          if an event comes, update the visible list.
- Server: if such socket has been opened: 
          propagate any event through that socket.

Is there something like a jQuery extension suitable for this purpose ?


Solution

  • You can take a look at node.js.

    But for a simple solution, all you need is define is setInterval that sends an ajax request every few seconds/minutes.

    //runs every 3 seconds
    setInterval(function(){
     //do ajax and refresh list
    },3000);
    

    Of course if the polling should happen very often ,this solution is not very good, in that case you should look at a long polling solution.