Zymic Forums

Webmaster resources

Zymic IRC Server

Chat in real time at irc.zymic.com - Learn More

Welcome

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.

left Zymic Webmaster ForumsWeb Design & DevelopmentClient Side ScriptingJavaScript right
  Closed Topic Start new topic
left right
TehBlizzy
post 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>
&lt;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? biggrin.gif

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
Go to the top of the page 
 
  + Quote Post
Andrew
post Mar 18 2009, 12:48 AM
Post #2


Hosting Abuse Staff
*******

Group: Moderators
Posts: 2,933
Joined: 14-February 08
From: Fort Myers FL, USA
Member No.: 10,089



Did you name the file file.php ?
also your missing your doctype declaration.
Go to the top of the page 
 
  + Quote Post
TehBlizzy
post Mar 18 2009, 01:53 AM
Post #3


Newbie
*

Group: Members
Posts: 12
Joined: 7-June 08
Member No.: 33,780



CODE
$File=fopen("ChatT.txt", "a");



I have no clue and have never used a doctype for anything, so I don't know the purpose of one... and where it goes.

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">


I added that to my index.php page and it didn't change anything.
Go to the top of the page 
 
  + Quote Post
MrTouz
post Mar 18 2009, 08:14 AM
Post #4


Outrageously Uber Ninja
*******

Group: Members
Posts: 1,196
Joined: 19-September 07
Member No.: 234



CODE
&lt;script language="Javascript">


At the very beginning of your code

i dunno if it has to do something with your error, or if it's how it is on your page but you should replace &lt; by <
Go to the top of the page 
 
  + Quote Post
swordz
post Mar 18 2009, 08:28 AM
Post #5


Outrageously Uber Ninja
*******

Group: Moderators
Posts: 1,805
Joined: 10-July 08
From: UK
Member No.: 44,994



Also, that <script></script> tag should be inside the<head></head> section.

swordz
Go to the top of the page 
 
  + Quote Post
TehBlizzy
post Mar 18 2009, 08:29 PM
Post #6


Newbie
*

Group: Members
Posts: 12
Joined: 7-June 08
Member No.: 33,780



I placed the script stuff inside the header and no changes, and the &lt; thing was just a mess up by the code thingy, its an actual < in my page
Go to the top of the page 
 
  + Quote Post
Andrew
post Mar 19 2009, 02:37 AM
Post #7


Hosting Abuse Staff
*******

Group: Moderators
Posts: 2,933
Joined: 14-February 08
From: Fort Myers FL, USA
Member No.: 10,089



Then it's not a messup, try deleting the one you see and replacing it. Might be surprised that it works.
Go to the top of the page 
 
  + Quote Post
TehBlizzy
post Mar 19 2009, 05:06 AM
Post #8


Newbie
*

Group: Members
Posts: 12
Joined: 7-June 08
Member No.: 33,780



Thats not the problem at all...Its a < even in notepad and in the "View Source" of the page...
Go to the top of the page 
 
  + Quote Post
MrTouz
post Mar 19 2009, 09:54 AM
Post #9


Outrageously Uber Ninja
*******

Group: Members
Posts: 1,196
Joined: 19-September 07
Member No.: 234



Yea delete the < and replace it by a <. Sometimes it's just that.

Sometimes i have errors i can't understand and just by copying my whole doc into a new page and save makes it works. Dunno why it happens but characters sometimes gets messed up.
Go to the top of the page 
 
  + Quote Post
Andrew
post Mar 19 2009, 03:46 PM
Post #10


Hosting Abuse Staff
*******

Group: Moderators
Posts: 2,933
Joined: 14-February 08
From: Fort Myers FL, USA
Member No.: 10,089



Your code doesn't do anything, the JavaScript doesn't do anything either.
Go to the top of the page 
 
  + Quote Post
TehBlizzy
post Mar 19 2009, 08:05 PM
Post #11


Newbie
*

Group: Members
Posts: 12
Joined: 7-June 08
Member No.: 33,780



CODE
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", data.length);
xmlHttp.setRequestHeader("Connection", "close");

Take that out and it works, but the PHP script doesn't get the message data when you send it.

And that is my problem... everything else is fine.

-

The < isn't a problem at all so stop suggesting things about it. I already know that isn't a problem. ( I've uploaded the page MANY times and have only changed the requestHeader part of the AJAX script so I know it isn't a problem...)
Go to the top of the page 
 
  + Quote Post
Ed
post Mar 19 2009, 10:32 PM
Post #12


Outrageously Uber Ninja
*******

Group: Administrators
Posts: 2,831
Joined: 11-March 07
From: UK
Member No.: 9



I've thrown it through the excellent js debugger firebug: https://addons.mozilla.org/en-US/firefox/addon/1843

The first bug is that you use an element id that doesn't exist 'address', either rename the 'UIMessage' to 'address', otherwise change line 21:

CODE
var Data = "UserMsg=" + encodeURI(document.getElementById("address").value);


The second bug is you're using 'data' as the object name when it should be 'Data':

CODE
xmlHttp.setRequestHeader("Content-length", data.length);


Those were the ones I spotted hope that helps.
Go to the top of the page 
 
  + Quote Post
TehBlizzy
post Mar 19 2009, 11:43 PM
Post #13


Newbie
*

Group: Members
Posts: 12
Joined: 7-June 08
Member No.: 33,780



Wow, I'm so blind to have missed that... Thanks for the help laugh.gif
Go to the top of the page 
 
  + Quote Post
TehBlizzy
post Mar 20 2009, 01:14 AM
Post #14


Newbie
*

Group: Members
Posts: 12
Joined: 7-June 08
Member No.: 33,780



Woohoo!! Its basically done now! I will add a username thing later once I get the sessions going, but for now its nothing but "Someone: (ur msg)"
Go to the top of the page 
 
  + Quote Post
TehBlizzy
post Mar 20 2009, 01:32 AM
Post #15


Newbie
*

Group: Members
Posts: 12
Joined: 7-June 08
Member No.: 33,780



Alrighty, its basically done now. Only thing is that will freeze up if you spam it... happened once already. Another thing is, is that IE doesn't seem to like it according to a friend of mine who tried it.
Go to the top of the page 
 
  + Quote Post
TehBlizzy
post Mar 20 2009, 05:53 PM
Post #16


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 :'(
Go to the top of the page 
 
  + Quote Post
 Closed Topic Start new topic
left right
0 Members:
left right
 


Lo-Fi Version Time is now: 23rd May 2013 - 12:08 PM