phpSensei Posted March 4, 2008 Share Posted March 4, 2008 Hey, alright i managed to create my chat script on my own, with obviously ajax, javascript, php and html.... very simple script, but it freezes after like couple of minutes, it works and everthing but makes the screen freez, and then the explorer just doesnt response anymore. I tried FireFox, same thing, i checked my browser for errors in my script, and none. I am sure the php part doesnt affect this ajax code: <script type="text/javascript" language="javascript"> function Focs(){ document.form1.message.focus(); var objDiv = document.getElementById("scroll"); objDiv.scrollTop = objDiv.scrollHeight; getChatText(); } function XMLHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.' + 'Consider upgrading your browser.'; } } var sendReq = XMLHttpRequestObject(); var receiveReq = XMLHttpRequestObject(); var mTimer; function getChatText(){ if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open('GET','get.php'); receiveReq.onreadystatechange = HandleMessage; receiveReq.send(null); } } function HandlPostMessage(){ if(document.add.message.value == ""){ alert("Please enter a message"); }else{ if (sendReq.readyState == 4 || sendReq.readyState == 0) { var message = document.add.message.value; sendReq.open('POST','send.php'); sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); sendReq.onreadystatechange = handleSendChat; sendReq.send('message=' + message); } } } function handleSendChat() { //Clear out the existing timer so we don't have //multiple timer instances running. clearInterval(mTimer); getChatText(); } function HandleMessage(){ if(receiveReq.readyState == 4 && receiveReq.status == 200){ var response = receiveReq.responseText; if(response){ document.getElementById('scroll').innerHTML = response; } } mTimer = setTimeout("getChatText();",2000); } </script> entire code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" language="javascript"> function ToggleSM(){ if(document.getElementById('sml1').style.display == ''){ document.getElementById('sml1').style.display = 'none'; }else{ document.getElementById('sml1').style.display = ''; } } function ToggleET(){ if(document.getElementById('editor').style.display == ''){ document.getElementById('editor').style.display = 'none'; }else{ document.getElementById('editor').style.display = ''; } } function Focs(){ document.form1.message.focus(); var objDiv = document.getElementById("scroll"); objDiv.scrollTop = objDiv.scrollHeight; getChatText(); } function XMLHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.' + 'Consider upgrading your browser.'; } } var sendReq = XMLHttpRequestObject(); var receiveReq = XMLHttpRequestObject(); var mTimer; function getChatText(){ if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open('GET','get.php'); receiveReq.onreadystatechange = HandleMessage; receiveReq.send(null); } } function HandlPostMessage(){ if(document.add.message.value == ""){ alert("Please enter a message"); }else{ if (sendReq.readyState == 4 || sendReq.readyState == 0) { var message = document.add.message.value; sendReq.open('POST','send.php'); sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); sendReq.onreadystatechange = handleSendChat; sendReq.send('message=' + message); } } } function handleSendChat() { //Clear out the existing timer so we don't have //multiple timer instances running. clearInterval(mTimer); getChatText(); } function HandleMessage(){ if(receiveReq.readyState == 4 && receiveReq.status == 200){ var response = receiveReq.responseText; if(response){ document.getElementById('scroll').innerHTML = response; } } mTimer = setTimeout("getChatText();",2000); } </script> <title>Chat Site - Fun, Friends, Community!</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <style type="text/css"> <!-- body { background-color: #EDF9FE; } .style2 { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } .border_dashed { border: 1px dashed #F0F0F0; } .style5 {font-size: 16px} .style6 {font-family: Arial, Helvetica, sans-serif; font-size: 16px; } .style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; } --> </style> <style type="text/css"> <!-- div.scroll { height: 410px; width: 660px; overflow: auto; } --> </style></head> <body onload="Focs();"> <div id="p_status"></div> <table width="53%" border="0" align="center" cellpadding="0" cellspacing="3" bgcolor="#CCCCCC"> <tr> <td height="408" align="left" valign="top" bgcolor="#FFFFFF"> <div id="scroll" class="scroll"></div></td> </tr> </table> <span class="style2"><b>- Add Message:</b> BBcodes allowed <i>([b][/b],[url = http://site.com][/url], [u][/u], [i][/i])</i> | [ <a href="#" onclick="ToggleSM();"> Show Smilies </a>]| [<a href="#" onclick="ToggleET();"> Show Editor </a>]</span> <br /> <table width="38%" border="0" align="center" cellpadding="0" cellspacing="3" bgcolor="#CCCCCC"> <tr> <td height="59" valign="top" bgcolor="#FFFFFF"> <form name="form1" id="form1" method="post" action=""> <table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td align="left" valign="top"><table width="100%" border="0" align="left" cellpadding="0" cellspacing="2" > <tr> <td height="2"><div id="sml1" style="display:none;"><img src="smileys/cool.jpg" width="18" height="18" /> <img src="smileys/happy.jpg" width="19" height="19" /> <img src="smileys/sad.jpg" width="18" height="19" /></div> <div id="editor" style="display:none;"><img src="icons/bold.jpg" width="18" height="15" /> <img src="icons/italic.jpg" width="18" height="15" /> <img src="icons/underline.jpg" width="15" height="15" /> <span class="style2"> [ <a href="#">url</a> ] </span></div></td> </tr> </table> <br /> <br /> <br /> <textarea name="message" cols="78" rows="10" class="border_dashed"></textarea></td> </tr> <tr> <td align="right"><input type="button" name="Button" value="Add Message" /></td> </tr> </table> </form></td> </tr> </table> <br /> <br /> </body> </html> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted March 5, 2008 Author Share Posted March 5, 2008 again, nvm, topic solved by me, yay Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.