我有这个聊天系统的一些问题。它不断给我这些错误,这是不应该的。
它一直给我一个弹出窗口说“Gopher”,这很烦人
我查看了代码,但找不到任何错误。有人知道有什么不对吗?
<script type="text/javascript">
var maxUsers = 50; // maximum is 50;
var updateResponse = "";
var stampResponse = "";
var resetResponse = "";
var stampRef = "";
var pollInterval = "";
var nUsers = [];
var nUserColor = ["#ff00ff","#ff6347","#1e90ff","#9932cc","#daa520","#a52a2a","#C0C0C0","#FFFF99","#CC6633","#FF9900"];
function parseUpdateResponse(){
var msgHistory = updateResponse;
var tmpUsers = msgHistory.match(/\~([^\~]+)\@/g);
if (tmpUsers != null)
{
tmpUsers = tmpUsers.join("").replace(/[\~\s]/g,"").split("@");
tmpUsers.length = tmpUsers.length-1;
nUsers = [];
var obj = new Object();
for (i=0; idx=tmpUsers[i]; i++)
{
obj[idx] = 1;
}
for (idx in obj)
{
nUsers.push(idx);
}
}
msgHistory = msgHistory.replace(/\#/g,"<br>").split("|");
for (i=0; i<nUsers.length; i++)
{
for (n=0; n<msgHistory.length; n++)
{
if(msgHistory[n].match(nUsers[i]) != null)
{
msgHistory[n] = msgHistory[n].replace(/\~([^\~]+)\~/,"<strong><font color="+nUserColor[i]+">$1: <\/font><\/strong>");
}
}
}
msgHistory = msgHistory.join("");
var nChatBox = document.getElementById('msgDisp');
nChatBox.innerHTML = msgHistory;
if (document.forms[0]['user'].value == "")
{
document.forms[0]['user'].focus();
}
else {
document.forms[0]['message'].focus();
}
if (nChatBox.scrollHeight > 0)
{
nChatBox.scrollTop = nChatBox.scrollHeight;
}
}
function updateChat(){
var updateRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
updateRequest.onreadystatechange = function()
{
if (updateRequest.readyState == 4)
{
if (updateRequest.status == 200)
{
updateResponse = updateRequest.responseText;
parseUpdateResponse();
}
else {
alert('Error updateChat.php File '+ updateRequest.statusText);
}
}
}
var forceGET = "?n="+ parseInt(Math.random()*999999999);
updateRequest.open("GET", "ChatFiles/updateChat.php"+forceGET, true);
updateRequest.send(null);
pollInterval = setInterval("pollStamp()",7500);
}
function parseStampResponse(){
var currStamp = stampResponse;
if (currStamp != stampRef)
{
stampRef = currStamp;
clearInterval(pollInterval);
updateChat();
}
}
function pollStamp(){
var stampRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
stampRequest.onreadystatechange = function()
{
if (stampRequest.readyState == 4)
{
if (stampRequest.status == 200)
{
stampResponse = stampRequest.responseText;
parseStampResponse();
}
else {
alert('gopher '+ stampRequest.statusText);
}
}
}
var forceGET = "?n="+ parseInt(Math.random()*999999999);
stampRequest.open("GET", "ChatFiles/pollStamp.php"+forceGET, true);
stampRequest.send(null);
}
function sendMessage(){
var sendRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
sendRequest.onreadystatechange = function()
{
if (sendRequest.readyState == 4)
{
if (sendRequest.status == 200)
{
pollStamp();
}
else {
alert('Error newMessage.php File '+ sendRequest.statusText);
}
}
}
var forceGET = "?n="+ parseInt(Math.random()*999999999);
var infoStr = forceGET +"&user="+document.forms[0]['user'].value;
infoStr += "&message="+document.forms[0]['message'].value;
document.forms[0]['message'].value = "";
sendRequest.open("GET", "ChatFiles/newMessage.php"+infoStr, true);
sendRequest.send(null);
}
function checkSubmit(evt){
var msgBox = document.forms[0]['message'];
msgBox.value = msgBox.value.replace(/[\r\n\~|#@]/g,"");
var key = (window.Event) ? evt.which : evt.keyCode;
if (key == 13)
{
if (msgBox.value == "" || document.forms[0]['user'].value == "")
{
return false;
}
if (nUsers.length == 0)
{
sendMessage();
return false;
}
else {
for (i=0; i<nUsers.length; i++)
{
if (document.forms[0]['user'].value == nUsers[i])
{
sendMessage();
return false;
}
}
}
if (nUsers.length < maxUsers)
{
sendMessage();
return false;
}
else {
alert('No more than '+maxUsers + ' Users at a time');
}
}
}
function parseResetResponse(){
document.getElementById('pWord').value = resetResponse;
if (resetResponse == "Okay")
{
nUsers.length = 0;
document.forms[0]['user'].value = "";
document.forms[0]['message'].value = "";
}
}
function resetChat(){
var resetRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
resetRequest.onreadystatechange = function()
{
if (resetRequest.readyState == 4)
{
if (resetRequest.status == 200)
{
resetResponse = resetRequest.responseText;
parseResetResponse();
}
else {
alert('Error resetChat.php File '+ resetRequest.statusText);
}
}
}
var forceGET = "?n="+ parseInt(Math.random()*999999999);
var infoStr = forceGET + "&admin="+document.getElementById('pWord').value;
resetRequest.open("GET", "ChatFiles/resetChat.php"+infoStr, true);
resetRequest.send(null);
}
onload=updateChat;
</script>
</head>
<body>
<div id='msgDisp' class='chatBox'></div>
<br>
<form action="">
<hr size=1>
<center>Press enter on your keyboard to submit your message</center>
<hr size=1>
<input type="hidden" name="user" value="<? echo("$_SESSION[usr_name]");?>" />
<br />
<textarea name='message' rows='4' cols='92' style='overflow:auto' onkeyup="checkSubmit(event)"></textarea>
</fieldset>
</form>
<br>
</body>
</html>
提前致谢,