2

I have a test django app.

In one page the test show the same question to all users.

I'd like that when a user answers correctly, send a signal to other active user's browser to refresh to the next question.

I have been learning about signals in django I learning work with them but I don't now how send the "refresh signal" to client browser.

I think that it can do with a javascript code that check if a certain value (actual question) change and if change reload the page but I don't know this language and the information that I find was confused.

Can anybody help me?

Many Thanks.

Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
Fran Sobrino
  • 23
  • 1
  • 3
  • Possible Duplicate: http://stackoverflow.com/questions/5479741/django-push-http-response-to-users – Spike Nov 12 '11 at 17:40

3 Answers3

5

There is no existing way to send a event from server to browser. But you can get your web page polling your server periodically (say every 5 seconds).

The code in javascript/jquery could be like the following

setInterval(function(){
    $.post("your_ajax_handler_url/is_answerd", userId, function(xhr){
       if(xhr.responseText == "answered"){
          location.reload(true);
       }  
    }
 }, 5000);
ComfortablyNumb
  • 3,391
  • 2
  • 14
  • 15
3

That is not at all what signals in Django are for. Signals in django are server side hooks that allow you perform tasks on the server when a certain even happens.

To 'send a refresh' to the browser, you need to use a server-push approach such as Comet. Alternatively you can get your clients to periodically poll the server to look for update.

Here's some links:

How to implement Server push / long polling / comet using PHP and Javascript

How do I implement basic "Long Polling"?

Community
  • 1
  • 1
Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • Thanks for the info. I've been read about comet but I think that it's too powerful to my proyect. I'll use the javascript optión to check updates. Many Thanks – Fran Sobrino Nov 13 '11 at 10:20
-1

What you need are coment(http://en.wikipedia.org/wiki/Comet_%28programming%29) and tornado(http://www.tornadoweb.org/)

LisztLi
  • 242
  • 1
  • 2
  • 6