Django刷新页面(如果其他用户更改数据) [英] Django refresh page if change data by other user
问题描述
我有一个测试django应用程序.
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.
我一直在学习有关django中的信号的知识,我正在与他们一起工作,但是现在我不知道如何将刷新信号"发送到客户端浏览器.
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.
我认为它可以与JavaScript代码一起使用,该代码检查某个值(实际问题)是否发生更改,并且更改是否会重新加载页面,但我不知道该语言,因此我发现所迷惑的信息.
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.
有人可以帮助我吗?
非常感谢.
推荐答案
尚无从服务器向浏览器发送事件的方法.但是您可以让您的网页定期轮询服务器(例如每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).
javascript/jquery中的代码可能如下所示
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);
这篇关于Django刷新页面(如果其他用户更改数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!