我正在使用PHP设置一个在线诊所注册系统。该系统有两个不同的用户组,即患者和诊所。病人会从可供选择的诊所中选择,在登记时,病人将获得一个唯一的排队号码。我已经做了所有这些,但我现在需要知道的是,当诊所的用户收到患者用户的新注册时,我如何创建警报?此警报是在不刷新网页的情况下通知诊所新注册的。
发布于 2013-03-18 23:33:13
使用Ajax从服务器获取最新(或未读)的通知。此Ajax可以从已登录的诊所用户的浏览器定期发送。
如果诊所没有在线,你也可以给它发电子邮件。
发布于 2013-03-19 00:40:32
我会用"XMLHttpRequest“来做这件事。在诊所的网页上,我会有类似如下的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>然后在诊所的网页上启动它:
<body onload="startItUp();">注意:这种方法对我来说在几个web应用程序中都工作得很好,但是,根据我的个人经验,如果你有很多诊所(比如说几百个)执行XMLHttpRequest,那么如果你有便宜的/通用的共享主机,那么你就会遇到服务器资源问题。
https://stackoverflow.com/questions/15480537
复制相似问题