I am working on having the following functionality for my mvc website. I want to have, for example 5 selected users voting on some question. When a user has voted, they will remain in a ‘waiting’ state until everyone has answered. Once those 5 users have answered, the page would autorefresh and I can populate the next question.
My basic thinking is that I need something like the following pseudocode to execute every so often (say 10 seconds) to check the status, possibly in jquery… then my controller can populate the next question.
while(condition not met) { } //wait
refresh()
Is there any simple way to fulfil this functionality?
Thanks.
Your thinking is exactly correct.
Uusing jQuery.get on a timer to your method to call jQuery.
Call into a url (route/controller) to see if voting has completed and examine the data in your resulting function that you set as a callback in your jQuery.get function.
If your condition is true, then jQuery can call another method using jQuery.load() to get the results and update your div such as:
$('#question').load('/Voting/NextQuestion/10');See the following for error handling when you call your jQuery methods
jQuery Error Handling