Implementing a live voting system Implementing a live voting system ajax ajax

Implementing a live voting system


You would have to query the server for a new question every few seconds.

The alternative is to hold the connection open until the server sends more data or it times out, which just reduces (but does not eliminate) the server hits. I think it is called "long polling". http://en.wikipedia.org/wiki/Push_technology


You will have to originate the connection from the client-side. The simplest solution is to have the page make an AJAX request every second or so. Web pages don't have to return immediately (they can take 30 seconds or more before responding without the connection timing out). This, opening one connection which doesn't respond until it has something to say, is "long-polling".


You could use setTimeout in JavaScript to make AJAX requests each few seconds to check whether there are new questions.

Yes, long polling might be better, but I'm sure it's a bit more complex. So if you are up to the job, go ahead and use it!

Here's a bit more info on the topic:http://www.webdevelopmentbits.com/avoiding-long-polling