当前位置: 代码迷 >> JavaScript >> XMLHTTP 怎么更好的处理无闪
  详细解决方案

XMLHTTP 怎么更好的处理无闪

热度:82   发布时间:2012-03-04 11:13:34.0
XMLHTTP 如何更好的处理无闪
<script   language= "JavaScript ">
function   getmsg()
{
var   msg   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
msg.open( "POST ", "msg.asp?tmp= "+Math.random(),false);
msg.send();
var   strmsg   =   unescape(msg.responseText);
window.msgbox.innerText   =   strmsg
}
window.setInterval( "getmsg() ",1000);
</script>

<textarea   rows= "20 "   name= "msgbox "   cols= "70 "> </textarea>

这样处理还是会有闪烁的感觉
请高手指教

------解决方案--------------------
上面的代码写错一个变量

<script language= "JavaScript ">
var strmsg1= " ";
function getmsg()
{
var msg = new ActiveXObject( "Microsoft.XMLHTTP ");
msg.open( "POST ", "msg.asp?tmp= "+Math.random(),false);
msg.send();
var strmsg = unescape(msg.responseText);
if (strmsg1==strmsg){
window.msgbox.innerText = strmsg;
strmsg1=strmsg;
}
}
window.setInterval( "getmsg() ",1000);
</script>

<textarea rows= "20 " name= "msgbox " cols= "70 "> </textarea>
  相关解决方案