2013-03-18 46 views
0

我正在使用PHP设置在线诊所注册系统。该系统有两个不同的用户组,即患者和诊所。患者将从可用的诊所中进行选择,并在注册后向患者发放唯一的队列号。我已经做了所有这些,但是我现在需要知道的是,如何在患者用户收到新注册时为诊所用户创建警报?此警报将通知诊所新的注册而不刷新网页。注册后向选定的用户创建警报

+0

您可能需要使用ajax。 – Pitchinnate 2013-03-18 15:31:37

回答

0

使用Ajax从服务器获取最新(或未读)通知。该Ajax可以定期从登录的诊所用户的浏览器发送。
如果诊所不在线,您也可以通过电子邮件向诊所发送电子邮件。

0

我会用“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();"> 

注:此方法已经在几个网站appliations但工作对我很好,从我个人的经验来看,如果你有很多诊所(几百个说法)执行XMLHttpRequest,那么如果你有便宜/共同的共享主机,你将遇到服务器资源问题。