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>
<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);
?>
$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...)