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
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
 
Start new topic
Replies
TehBlizzy
post 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 :'(
Go to the top of the page 
 
  + Quote Post

Posts in this topic

 Closed Topic Start new topic
left right
0 Members:
left right
 


Lo-Fi Version Time is now: 20th June 2013 - 06:03 AM