html(主页面)代码:
<div id="rbbox">
<a class="button" οnclick="closeBox()">关闭</a>
<iframe id="iframeyxj" src="yxjiframe.html" frameborder="0" height="150" width="180" scrolling="no"></iframe>
</div>
********************************
html(弹出的框)代码:
<body>
<table>
<tr>
<td> 系统消息:</td>
</tr>
<tr>
<td></td>
<td><span style="font-size: 13px;color: red;">你好!</span></td>
</tr>
</table>
</body>
********************************
js代码:
//每5秒请求一次服务器
window.οnlοad=function(){
window.setInterval("CheckIsNewSystemInfo()",5000);
}
function CheckIsNewSystemInfo()
{
var sync=true;
var req = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
req.open('POST','yxjMessage.action?id=iop',sync);
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
req.send("");
req.onReadyStateChange=function(){
if(req.readyState==4){
if(req.responseText.length>0){
var obj=eval(req.responseText);
if(obj=="ok")
{
ifmessage(obj);
}
}
}
}
/*
$.ajax({
type:"POST",
url:"yxjMessage.action",
data:"name=lop",
success:function(msg){
alert(mag[0]);
//ifmessage(msg[0]);
}
});
*/
}
function ifmessage(msg)
{
showBox();
}
function showBox(o){
if (o==undefined) o=document.getElementById("rbbox");
o.style.height=150;
if(o.style.display==="none")
{
o.style.display="block";
}
}
function closeBox(){
var rbbox = document.getElementById("rbbox");
document.getElementById("rbbox").style.display="none";
}
*****************************************************
后台(webwork):
public String execute() throws Exception {
PrintWriter pwriter = response.getWriter();
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
JSONArray json = new JSONArray();
List list = new ArrayList();
list.add("ok");
pwriter.write(json.fromObject(list).toString());
pwriter.flush();
pwriter.close();
return null;
}