What Is Wrong? |
||
Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.
In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.
Zymic Webmaster Forums Web Design & Development Client Side Scripting JavaScript |
||
What Is Wrong? |
||
Mar 17 2009, 02:29 PM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 12 Joined: 7-June 08 Member No.: 33,780 |
CODE <html> <head> <title> Chatroom </title> </head> <script language="Javascript"> var xmlHttp function sendMessage() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var Msg=document.getElementById("UIMessage"); var url="ChatFunc.php"; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("POST",url,true); var Data = "UserMsg=" + encodeURI(document.getElementById("address").value); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Content-length", data.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(Data); } function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById("ChatT").innerHTML+=xmlHttp.responseText; } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } </script> <body> <style type="text/css"> body { background-color: #000000; } div#Main { position: block; width: 600px; height: 500px; margin: auto; border-style: solid; border-color: #FF0000; border-width: 1px; } div#Chat { position: relative; width: 395px; height: 345px; border-style: solid; border-color: #FF0000; border-width: 1px; left: 5px; top: 5px; color: #FF0000; } p#ChatT { position: relative; overflow-y: scroll; height: 285px; left: 5px; width: 390px; } div#ChatH { color: #FF0000; font-size: 25px; text-align: center; border-bottom-style: solid; border-bottom-width: 1px; font-family: Comic Sans MS; } div#UsersH { color: #FF0000; font-size: 25px; text-align: center; border-bottom-style: solid; border-bottom-width: 1px; font-family: Comic Sans MS; } div#Users { position: absolute; width: 180px; height: 345px; border-style: solid; border-color: #FF0000; border-width: 1px; left: 750px; top: 15px; } p#UsersT { position: relative; overflow-y: scroll; height: 285px; left: 5px; width: 175px; color: #FF0000; font-size: 20px; } div#Input { position: relative; width: 585px; height: 135px; border-style: solid; border-color: #FF0000; border-width: 1px; top: 10px; left: 5px; color: #FF0000; font-size: 24px; font-family: Comic Sans MS; } div#Input p { position: relative; margin: auto; } </style> <div id="Main"> <div id="Chat"> <div id="ChatH"> CHATROOM </div> <p id="ChatT"> lol </p> </div> <div id="Users"> <div id="UsersH"> USERS </div> <p id="UsersT"> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> lol <br> </p> </div> <div id="Input"> <p> Message:<input type="text" id="UIMessage" size="64" maxlength="64"> <button onClick="sendMessage()">SEND</button> </p> </div> </div> </body> </html> Please ignore my horrible layout because I a too lazy to put my CSS in another file xD Basically, if I take out the "requestHeader" lines the page actually does something, but when I add it the script does nothing. I know this because when I click Send the ChatT box becomes empty. But, my PHP script is not receiving the UserMsg value I am sending to it when it actually works. ChatFunc.php CODE <?php $UserMsg=$_POST['UserMsg']; $File=fopen("ChatT.txt", "a"); fwrite($File,$UserMsg); fclose($File); ?> If I set $UserMsg to a certain value, like "Hello", it writes it to the file. If I assign it to the post data it writes a "0" which Im sure means null or something. Any tips? The site is http://tehblizzy.uuuq.com/ and the text file is (tehblizzy.uuuq.com/ChatT.txt) (Excuse my bad language in it, I was very po'd at it at the time...) This post has been edited by zpcs: Dec 18 2012, 11:56 AM
Reason for edit: Broken URL Link Removed then Broken URL Link allowanced for Descriptive URL Link so as not to disturb content
|
|
|
![]() |
Mar 20 2009, 05:53 PM
Post
#2
|
|
|
Newbie ![]() Group: Members Posts: 12 Joined: 7-June 08 Member No.: 33,780 |
Now there ish a new problem. Sessions aren't saving. I know I'm doing it right so its not my coding that has probs. The session thing may have been posted somewhere in these forums on how to fix it or why it is happening, but using the search tool comes up with too many results. SO yea, sessions don't work :'(
|
|
|
TehBlizzy What Is Wrong? Mar 17 2009, 02:29 PM
Trippin7464 Did you name the file file.php ?
also your missing... Mar 18 2009, 12:48 AM
TehBlizzy $File=fopen("ChatT.txt", "a... Mar 18 2009, 01:53 AM
MrTouz <script language="Javascript">
... Mar 18 2009, 08:14 AM
swordz Also, that <script></script> tag shou... Mar 18 2009, 08:28 AM
TehBlizzy I placed the script stuff inside the header and no... Mar 18 2009, 08:29 PM
Andrew Then it's not a messup, try deleting the one y... Mar 19 2009, 02:37 AM
TehBlizzy Thats not the problem at all...Its a < even in ... Mar 19 2009, 05:06 AM
MrTouz Yea delete the < and replace it by a <. Some... Mar 19 2009, 09:54 AM
Andrew Your code doesn't do anything, the JavaScript ... Mar 19 2009, 03:46 PM
TehBlizzy xmlHttp.setRequestHeader("Content-type... Mar 19 2009, 08:05 PM
Bread I've thrown it through the excellent js debugg... Mar 19 2009, 10:32 PM
TehBlizzy Wow, I'm so blind to have missed that... Thank... Mar 19 2009, 11:43 PM
TehBlizzy Woohoo!! Its basically done now! I wil... Mar 20 2009, 01:14 AM
TehBlizzy Alrighty, its basically done now. Only thing is th... Mar 20 2009, 01:32 AM ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users) |
||
| 0 Members: | ||
Forum Jump |
||
| Lo-Fi Version | Time is now: 20th June 2013 - 06:03 AM |