Django refresh page if change data by other user

柔情痞子 提交于 2019-12-06 05:30:29

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);
Timmy O'Mahony

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"?

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!