首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在注册时为所选用户创建警报

在注册时为所选用户创建警报
EN

Stack Overflow用户
提问于 2013-03-18 23:27:58
回答 2查看 69关注 0票数 0

我正在使用PHP设置一个在线诊所注册系统。该系统有两个不同的用户组,即患者和诊所。病人会从可供选择的诊所中选择,在登记时,病人将获得一个唯一的排队号码。我已经做了所有这些,但我现在需要知道的是,当诊所的用户收到患者用户的新注册时,我如何创建警报?此警报是在不刷新网页的情况下通知诊所新注册的。

EN

回答 2

Stack Overflow用户

发布于 2013-03-18 23:33:13

使用Ajax从服务器获取最新(或未读)的通知。此Ajax可以从已登录的诊所用户的浏览器定期发送。

如果诊所没有在线,你也可以给它发电子邮件。

票数 0
EN

Stack Overflow用户

发布于 2013-03-19 00:40:32

我会用"XMLHttpRequest“来做这件事。在诊所的网页上,我会有类似如下的javascript:

代码语言:javascript
复制
<script type="text/javascript">
var comm = new Array(), frameTime = 0, regTime = 0;

function startItUp(){
    animate();
}

window.requestAnimFrame = (function(){//from Paul Irish
    return  window.requestAnimationFrame       || 
    window.webkitRequestAnimationFrame || 
    window.mozRequestAnimationFrame    || 
    window.oRequestAnimationFrame      || 
    window.msRequestAnimationFrame     || 
    function(callback, element){
        window.setTimeout(callback, 1000 / 60);
    };
})();
function animate() {
    frameTime = Date.now();
        if(regTime < frameTime){
            comm.push( new getRegistrants() );
            regTime = frameTime + 8000;//how often to call the php page and check for new patients
        }
    }
    requestAnimFrame( animate );
}
function getRegistrants(){
    this.client = new XMLHttpRequest();
    this.client.onload  = function () {
        var registrantData = this.responseText;
        //Parse the registrant data displayed by php page here and make the alert or div popup...
        alert(parsedRegistrantName + ' has registered.');

    }
    this.client.open('POST', 'getRegistrants.php');//This page would have a session that would contain your logged in clinic's ID and would just output registrant(patient) data that you can parse
    this.client.send();
}
</script>

然后在诊所的网页上启动它:

代码语言:javascript
复制
<body onload="startItUp();">

注意:这种方法对我来说在几个web应用程序中都工作得很好,但是,根据我的个人经验,如果你有很多诊所(比如说几百个)执行XMLHttpRequest,那么如果你有便宜的/通用的共享主机,那么你就会遇到服务器资源问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15480537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档