No refreshing chat room (text message companion chat program)

Source: Internet
Author: User

Index. asp on the home page:
<% @ Language = "VBScript" codePage = "936" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd">
<! -- # Include file = "conn. asp" -->
<! -- # Include file = "chklogin. asp" -->
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "refresh" content = "3600">
<Title> Chat Room </title>
<Link href = "style.css" rel = "stylesheet" type = "text/CSS">
</Head>

<Body>

<Script language = "JavaScript">
VaR t_room, t_log, t_user;
VaR phone, srcphone, province, content;
VaR room, log, user, myroomid = 0, PID;
Log = array ();
User = array ();
<%
Set rs=conn.exe cute ("select top 1 chat_id as ID from chat_log where chat_id in (select top 50 chat_id from chat_log order by chat_id DESC) order by chat_id ")
Response. Write ("pid =" & RS ("ID ")&";")
%>
</SCRIPT>
<Script language = "JavaScript" src = "function. js"> </SCRIPT>
<Table width = "768" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Form name = "form1" method = "Post" Action = "" onsubmit = "Return false;">
<Tr>
<TD width = "11%" valign = "TOP"> <Div align = "center">
<Select id = "chat_room" onchange = "change_room ();"> </SELECT> <br>
<Select id = "chat_user" name = "select" size = "25" onchange = "chat_user_change ();">
</SELECT> <br>
<Span onclick = "load_room ();" style = "cursor: hand;"> refresh the room list </span> <br>
<Span onclick = "load_user ();" style = "cursor: hand;"> refresh the user list </span> </div> </TD>
<TD width = "89%" valign = "TOP"> <textarea name = "log" rows = "30" Wrap = "virtual" id = "log"> </textarea> </TD>
</Tr>
<Tr>
<TD> <select name = "tophone" onchange = "srcphone = This. value;"> </SELECT> </TD>
<TD> <input name = "content" type = "text" id = "content" size = "90" maxlength = "140" onkeydown = "If (event. keycode = 13) {send ();} ">
<Input name = "sendtoserver" type = "button" id = "sendtoserver" onclick = "Send ();" value = "send">
<Input type = "button" name = "Submit" value = "exit" onclick = "window. Location. href = 'logout. asp ';"> </TD>
</Tr>
</Form>
</Table>
</Body>
</Html>

Key function. JS:
// JavaScript document
Window. onload = function Init ()
{
Load_log ();
Load_user ();
Load_room ();
}
Function getpage (URL)
{
VaR xml = new activexobject ("Microsoft. XMLHTTP ");
XML. Open ("get", URL, false );
XML. Send ();
Return Unescape (XML. responsetext );
}
Function postdata (URL, body)
{
VaR xml = new activexobject ("Microsoft. XMLHTTP ");
XML. Open ("Post", URL, false );
XML. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ")
XML. setRequestHeader ("Content-Length", escape (body). length)
XML. Send (body );
}
Function load_room ()
{
VaR value = getpage ("chat_room.asp ");
VaR STR = value. Split ("#");
VaR ID, roomname, temp;
Room = new activexobject ("scripting. Dictionary ");
VaR I = Str. Length-1;
While (I --> 0)
{
Temp = STR [I]. Split ("*");
Id = temp [0];
Roomname = temp [1];
Room. Add (ID, roomname );
}
Show_room ();
// T_room = setTimeout ("load_room ();", 60000 );
}
Function show_room ()
{
VaR I;
For (I = Document. form1.chat _ room. Options. length; I> 0; I --)
{
Document. form1.chat _ room. Options. Remove (I-1 );
}
Document. form1.chat _ room. Options. Add (New Option ("all", 0 ));
A = (New vbarray (room. Items (). toarray ();
For (I in)
{
Document. form1.chat _ room. Options. Add (New Option (a [I], I ));
}
Document. form1.chat _ room. selectedindex = myroomid;
}
Function load_user ()
{
VaR value = getpage ("chat_user.asp ");
VaR STR = value. Split ("#");
VaR userid, nickname, roomid, temp;
VaR I;
I = user. Length-1;
While (I --> = 0)
{
User. Pop ();
}
I = Str. Length-1;
While (I --> 0)
{
Temp = STR [I]. Split ("*");
Userid = temp [0];
Nickname = temp [1];
Roomid = temp [2];
User. Push (userid, nickname, roomid );
}
Show_user ();
// T_user = setTimeout ("load_user ();", 60000 );
}
Function show_user ()
{
VaR I;
For (I = Document. form1.chat _ User. Options. length; I> 0; I --)
{
Document. form1.chat _ User. Options. Remove (I-1 );
}
Document. form1.chat _ User. Options. Add (New Option ("all", 278810 ));
I = user. Length-1;
While (I> = 0)
{
If (User [I] = myroomid | myroomid = 0)
{
Document. form1.chat _ User. Options. Add (New Option (User [I-1], user [I-2]);
}
I-= 3;
}
Document. form1.chat _ User. selectedindex = myroomid;
}
Function load_log ()
{
VaR value = getpage ("chat_log.asp? Id = "+ PID );
VaR STR = value. Split ("#");
VaR ID, roomid, msgbody;
VaR I = Str. Length-1;
While (I --> 0)
{
Temp = STR [I]. Split ("*");
Id = temp [0];
Roomid = temp [1];
Msgbody = temp [2];
Log. Push (roomid, msgbody );
PID = ID;
}
If (Str. length> 1)
{
Show_log ();
}
T_log = setTimeout ("load_log ();", 5000 );
}
Function show_log ()
{
VaR I = log. Length-1;
VaR STR = "";
While (I> = 0)
{
If (log [I-1] = myroomid | myroomid = 0)
{
STR + = log [I]. tostring () + "/N ";
}
I-= 2;
}
Document. form1.log. value = STR;
}
Function change_room ()
{
Myroomid = Document. form1.chat _ room. selectedindex;
// Cleartimeout (t_room );
// Cleartimeout (t_user );
// Cleartimeout (t_log );
Show_room ();
Show_user ();
Show_log ();
}
Function chat_user_change ()
{
VaR I;
For (I = 0; I <document. form1.chat _ User. Options. length; I ++)
{
If (document. form1.chat _ User. Options [I]. Selected)
{
VaR J;
For (j = 0; j <document. form1.tophone. Options. length; j ++)
If (document. form1.tophone. Options [J]. Text = Document. form1.chat _ User. Options [I]. Text)
Break;
If (j = Document. form1.tophone. Options. length)
{
Document. form1.tophone. Options. Add (New Option (document. form1.chat _ User. Options [I]. Text, document. form1.chat _ User. Value ));
}
Document. form1.tophone. Options [J]. Selected = true;
}
}
Srcphone = Document. form1.chat _ User. value;
}
Function send ()
{
Try
{
VaR body = "content =" + escape (document. form1.content. Value) + "& srcphone =" + escape (srcphone );
// Body = escape (body );
Postdata ("chat_send.asp", body );
// Getpage ("chat_send.asp? "+ Body );
Document. form1.content. value = "";
Document. form1.content. Focus ();
}
Catch (E)
{
Alert (E. Description );
}
}

Return chat_log.asp:
<! -- # Include file = "conn. asp" -->
<! -- # Include file = "chklogin. asp" -->
<%
Response. expires =-1
Response. expiresabsolute = now ()-1
Response. cachecontrol = "no-Cache"
If isnumeric (Request ("ID") then
Set rs1_conn.exe cute ("select top 50 * From chat_log where tophone is not null and chat_id>" & request ("ID") & "order by chat_id DESC ")
While not Rs. EOF
Response. write (escape (RS ("chat_id") & "*" & RS ("roomid") & "*" & RS ("sendtime") & RS ("msgbody ") &"#"))
Rs. movenext
Wend
End if
%>

Get the room list chat_room.asp:
<! -- # Include file = "conn. asp" -->
<! -- # Include file = "chklogin. asp" -->
<%
Response. expires =-1
Response. expiresabsolute = now ()-1
Response. cachecontrol = "no-Cache"
Set rs1_conn.exe cute ("select * From chat_room order by id desc ")
While not Rs. EOF
Response. Write (escape (RS ("ID") & "*" & RS ("roomname ")&"#"))
Rs. movenext
Wend
%>

Obtains online user chat_user.asp:
<! -- # Include file = "conn. asp" -->
<! -- # Include file = "chklogin. asp" -->
<%
Response. expires =-1
Response. expiresabsolute = now ()-1
Response. cachecontrol = "no-Cache"
Set rs1_conn.exe cute ("select srcphone, userid, nickname = case left (phone, 3) when '000000' then nickname + '· 'when' 133 'then nickname +' · 'else nickname end, roomid from DBO. chat_user where State = 1 order by userid ")
While not Rs. EOF
Response. write (escape (RS ("srcphone") & RS ("userid") & "*" & RS ("nickname") & "*" & RS ("roomid ") &"#"))
Rs. movenext
Wend
%>

Responsible for sending chat content chat_send.asp:
<! -- # Include file = "conn. asp" -->
<! -- # Include file = "chklogin. asp" -->
<%
'Exec chat '000000', 'me', '000000', '000000', '1'
Phone = SESSION ("phone ")
Province = SESSION ("Province ")
Content = request ("content ")
Srcphone = request ("srcphone ")
Conn.exe cute ("Exec chat" & phone & "','" & content & "','" & srcphone & "','" & Province &"', '0 '")
'Savefile "chat'" & phone & "','" & content & "','" & srcphone & "','" & Province & "', '1 '"
'Function SaveFile (STR)
'Set FSO = server. Createobject ("scripting. FileSystemObject ")
'Set F1 = FSO. opentextfile (server. mappath ("./test.txt"), 8, true)
'F1.write (STR)
'F1.close
'Set FSO = nothing
'End Function
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.