日期:2014-05-20  浏览次数:20440 次

ajax聊天室不刷新问题 超急!!好不容易有兴趣学ajax了.解决立马给分!!!
出现的问题是:   点击发言按钮后,新的数据确实到access数据库里了,但是前台聊天室界面一直显示的还有老的数据,没有刷新.比如以前有一条信息: "你好 ".当发表第二条信息: "中国人 "后,“中国人”这条信息成功的到数据库里了,但是在前台还一直是 "你好 "这条信息.我能确定更新消息的异步请求是一直在执行的,但就是不知道为什么不会取更新后的信息.下面是源码,请大家帮帮我:
<script   type= "text/javascript ">
//////////////////////////////////////////更新消息的异步
var   xmlHttp;
function   createXMLHttpRequest()   {
        if   (window.ActiveXObject)   {
                xmlHttp   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
        }  
        else   if   (window.XMLHttpRequest)   {
                xmlHttp   =   new   XMLHttpRequest();
        }
}
       
function   startRequest()   {
        createXMLHttpRequest();
        xmlHttp.onreadystatechange   =   displayinfo;
        xmlHttp.open( "GET ",   "getnewmessage.aspx ",   true);
        xmlHttp.send(null);
}
       
function   displayinfo()   {
        if(xmlHttp.readyState   ==   4)   {
                if(xmlHttp.status   ==   200)   {
                        showinfo();
                }
        }
}
function   showinfo()
{
        var   chatlist=document.getElementById( "content ");
        if(chatlist.hasChildNodes())
        chatlist.removeChild(chatlist.childNodes[0]);
        var   info=document.createTextNode(xmlHttp.responseText);
        document.getElementById( "content ").appendChild(info);
        window.setTimeout( "startRequest() ",2500);
}

////////////////////////////////////////////////发送消息的异步
var   sendxmlhttp;
function   createSendXMLHttpRequest()   {
        if   (window.ActiveXObject)   {
                sendxmlhttp   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
        }  
        else   if   (window.XMLHttpRequest)   {
                sendxmlhttp   =   new   XMLHttpRequest();
        }
}
       
function   sendmessage()   {
        createSendXMLHttpRequest();
        var   para= "para= "+document.getElementById( "info ").value;
        sendxmlhttp.onreadystatechange   =   getresult;
        sendxmlhttp.open( "GET ",   "addmessage.aspx? "+para,   true);
        sendxmlhttp.send(null);
}
       
function   getresult()   {
        if(sendxmlhttp.readyState   ==   4)   {
                if(sendxmlhttp.status   ==   200)   {