1. 'responseFunc' is undefined - line 1 of ajax.js file
2. Expected '}' - chatbox.js file
3. Object expected in chat.html file, Code:0, URI:http://www.globalconferencing.net/chat%20box/chat.html
To further give another example when I test that chat I enter a user name hit sign in and nothing happens. The user name is not being posted anywhere and the message is doing nothing also.... Can somebody please help...
Here is the code for Chat.html
<html>
<link rel="stylesheet" type="text/css" href="cb_style.css">
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript" src="chatbox.js"></script><html>
<head>
<title>Welcome to 1888vcrooms.com Chat Room</title>
</head>
<body onbeforeunload="signInForm.signInButt.name='signOut';signInOut()" onload="hideShow('hide')">
<h1>1888vcrooms.com Chat Room</h1>
<form id="signInForm">
<input id="userName" type="text">
<input id="signInButt" name="signIn" type="submit" value="Sign in">
<span id="signInName">User name</span>
</form>
<div id="chatBox"></div>
<div id="usersOnLine"></div>
<form id="messageForm">
<input id="message" type="text">
<input id="send" type="submit" value="Send">
<div id="serverRes"></div>
</form>
</body>
</html>
Here is the code for ajax.js
Ajax_Send("POST","my_url","name1=ahmad&name2=511",reponseFunc);
Here is the code for chatbox.js
function hideShow(hs){
if(hs=="hide"){
signInForm.signInButt.value="Sign in"
signInForm.signInButt.name="signIn"
messageForm.style.display="none"
signInForm.userName.style.display="block"
signInName.innerHTML=""
}
if(hs=="show"){
signInForm.signInButt.value="Sign out"
signInForm.signInButt.name="signOut"
messageForm.style.display="block"
signInForm.userName.style.display="none"
signInName.innerHTML=signInForm.userName.value
}
}
// Sign in and Out
function signInOut(){
// Validationif (signInForm.userName.value=="" || signInForm.userName.value.indexOf(" ")>-1)
{alert("Not valid user name\nPlease make sure your user name didn't contains a space\nOr it's not empty.");
signInForm.userName.focus();
return false;
}
// Sign in
if (signInForm.signInButt.name=="signIn"){
data="user=" + signInForm.userName.value +"&oper=signin"
Ajax_Send("POST","users.php",data,checkSignIn);
return false
}
}
// Sign in response
function checkSignIn(res){
if(res=="userexist"){alert("The user name you typed is already exist\nPlease try another one");
return false;
}
if(res=="signin"){
hideShow("show")
messageForm.message.focus()
updateInterval=setInterval("updateInfo()",3000);
serverRes.innerHTML="Sign in"
}
}
// Send message
function sendMessage(){
data="message="+messageForm.message.value+"&user="+signInForm.userName.value
serverRes.innerHTML="Sending"
Ajax_Send("POST","send.php",data,sentOk)
}
// Sent Ok
function sentOk(res){
if(res=="sentok"){
messageForm.message.value=""
messageForm.message.focus()
serverRes.innerHTML="Sent"}
else{
serverRes.innerHTML="Not sent"
}
}
lastReceived=0
// Update info
function updateInfo(){
serverRes.innerHTML="Updating"
Ajax_Send("POST","users.php","",showUsers)
Ajax_Send("POST","receive.php","lastreceived="+lastReceived,showMessages)
}
// update online users
function showUsers(res){
usersOnLine.innerHTML=res
}
// Update messages view
function showMessages(res){
serverRes.innerHTML=""
msgTmArr=res.split("<SRVTM>")
lastReceived=msgTmArr[1]
messages=document.createElement("span")
messages.innerHTML=msgTmArr[0]
chatBox.appendChild(messages)
chatBox.scrollTop=chatBox.scrollHeight
// Sign out
if (signInForm.signInButt.name=="signOut"){
data="user=" + signInForm.userName.value +"&oper=signout"
Ajax_Send("POST","users.php",data,checkSignOut);
return false;}
// Sign out response
function checkSignOut(res){
if(res=="usernotfound"){
serverRes.innerHTML="Sign out error";
res="signout"
}
if(res=="signout"){
hideShow("hide")
signInForm.userName.focus()
clearInterval(updateInterval)
serverRes.innerHTML="Sign out"
return false
}
}
here is the code for users.php
<?PHP
$olu=join("<br>",$onlineusers_file);
echo $olu;
function saveUsers($onlineusers_file){
$file_save=fopen("onlineusers.txt","w+");
flock($file_save,LOCK_EX);
for($line=0;$line<count($onlineusers_file);$line++){
fputs($file_save,$onlineusers_file[$line]."\n");
};
flock($file_save,LOCK_UN);
fclose($file_save);
}
$onlineusers_file=file("onlineusers.txt",FILE_IGNORE_NEW_LINES);
if (isset($_POST['user'],$_POST['oper'])){
$user=$_POST['user'];
$oper=$_POST['oper'];
$userexist=in_array($user,$onlineusers_file);
if ($userexist)$userindex=array_search($user,$onlineusers_file);
if($oper=="signin" && $userexist==false){
$onlineusers_file[]=$user;
saveUsers($onlineusers_file);
echo "signin";
exit();
}if($oper=="signin" && $userexist==true){
echo "userexist";
exit();
}
}
if($oper=="signout" && $userexist==true){
array_splice($onlineusers_file,$userindex,1);
saveUsers($onlineusers_file);
echo "signout";exit();
}
if($oper=="signout" && $userexist==false){
echo "usernotfound";
exit();
}
?>
Here is the code forsend.php
<?php
$message=strip_tags($_POST['message']);
$message=stripslashes($message);
$user=$_POST['user'];
$room_file=file("room1.txt",FILE_IGNORE_NEW_LINES);
$room_file[]=time()."<!@!>".$user.": ".$message;
if (count($room_file)>20)$room_file=array_slice($room_file,1);
$file_save=fopen("room1.txt","w+");
flock($file_save,LOCK_EX);
for($line=0;$line<count($room_file);$line++){
fputs($file_save,$room_file[$line]."\n");
};
flock($file_save,LOCK_UN);
fclose($file_save);
echo "sentok";
exit();
?>
here is the code for receive.php
<?php
$lastreceived=$_POST['lastreceived'];
$room_file=file("room1.txt",FILE_IGNORE_NEW_LINES);
for($line=0;$line<count($room_file);$line++){
$messageArr=split("<!@!>",$room_file[$line]);
if($messageArr[0]>$lastreceived)echo $messageArr[1]."<br>";
}
echo "<SRVTM>".$messageArr[0];
?>
If anyone can help it would be much appreciated.........

New Topic/Question
Reply



MultiQuote




|