服务端用户的消息放到 Session 中,
客户端 AJAX 通讯:
var req = null;
function loadMessages(){
req = new ActiveXObject("msxml2.xmlhttp");
req.open("get","http://myserver/messages.jsp",true);
req.onreadystatechange = listen;
req.send;
}
function listen(){
if( req == null) return;
if(req.readyState == 4){ // completed ?
if( req.status != 200){
}
}
req = null; // 丢弃状态,以免出现意外错误。
}
var logger = document.createElement("div");
log.styleText = "zIndex:3;position:absolute;left:0;right:0;"
+ "botton:0;height:25px;background:ivory;";
function log(sMsg){
document.body.appendChild(logger);
logger.innerText = sMsg;
window.setTimeout('hideLogger',3000); // 3 秒后隐藏消息。
}
function hideLogger(){
logger.innerText = "";
document.body.removeChild(logger);
}
window.setTimeout('loadMessages',30 * 1000);