跪求ajax问题
<br /><!DOCUTYPE html><br /><html><br /> <head><br /> <title>聊天窗口</title><br /> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"><br /> </head><br /> <script type="text/javascript"><br /> window.resizeTo(580,650);<br /> window.setInterval("getMessage()", 3000);<br /> <br /> function getXmlHttpObject(){<br /> var xmlHttpRequest;<br /> //不同的浏览器获取对象xmlhttprequest对象方法不一样<br /> if(window.ActiveXObject){<br /> xmlHttpRequest =new ActiveXObject("Microsoft.XMLHTTP");<br /> }else{<br /> xmlHttpRequest =new XMLHttpRequest();<br /> }<br /> return xmlHttpRequest;<br /> }<br /><br /> function getMessage()<br /> {<br /> var myXmlHttpRequest = getXmlHttpObject();<br /><br /> if(myXmlHttpRequest)<br /> {<br /> var url = "getMessage.php";<br /> var data = "getter=<?php @session_start(); echo $_SESSION['username'];?>&sender=<?php echo $_GET['username'];?>";<br /><br /> myXmlHttpRequest.open("post",url,true);<br /> myXmlHttpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");<br /><br /> myXmlHttpRequest.onreadystatechange=function()<br /> {<br /> if(myXmlHttpRequest.readyState==4)<br /> {<br /> if(myXmlHttpRequest.status==200)<br /> {<br /> //接收<br /> var mes=myXmlHttpRequest.responseXML;<br /> <br /> window.alert(mes); //这里打印出来老是为null<br /> }<br /> }<br /> }<br /> myXmlHttpRequest.send(data);<br /> }<br /><br /> }<br /><br /> function sendMessage()<br /> {<br /> var myXmlHttpRequest = getXmlHttpObject();<br /><br /> if(myXmlHttpRequest)<br /> {<br /> var url = "sendMessage.php";<br /> var data = "con=" + $('con').value +"&getter=<?php echo $_GET['username'];?>"+"&sender=<?php @session_start(); echo $_SESSION['username'];?>";<br /><br /> myXmlHttpRequest.open("post",url,true);<br /> myXmlHttpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");<br /> myXmlHttpRequest.onreadystatechange=function()<br /> {<br /> if(myXmlHttpRequest.readyState==4)<br /> {<br /> if(myXmlHttpRequest.status==200)<br /> {<br /><br /> }<br /> }<br /> }<br /> myXmlHttpRequest.send(data);<br /> }<br /> <br /> }<br /><br /> function $(id)<br /> {<br /> return document.getElementById(id);<br /> }<br /> </script><br /> <body><br /> <center><br /> <h2><span style="color:red;"><?php @session_start(); echo $_SESSION['username'];?></span>跟<span style="color:red;"><?php echo $_GET['username'];?></span>聊天</h2><br /> <textarea name="context" rows="20" cols="70"></textarea><br/><br /> <input style="width:300px" type="text" name="sendcontext" id="con"><br /> <input type="button" name="send" onclick="sendMessage();" value="发送"><br /> </center><br /> </body><br /><br /></html><br />
<br /><?php<br /> include "MessageServer.class.php";<br /> @header( 'Content-Type:text/xml;charset=utf-8'); <br /> @header("Cache-Control: no-cache");<br /> $getter = $_POST['getter'];<br /> $sender = $_POST['sender'];<br /><br /> //调用MessageSerive获取信息<br /> $messageServer = new MessageServer();<br /><br /> $messList = $messageServer->getMessage($getter, $sender);<br /><br /> echo $messList;<br /> <br />?><br />