2013-03-18 44 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,那麼如果你有便宜/共同的共享主機,你將遇到服務器資源問題。