分享
 
 
 

无刷新聊天室(短信陪聊程序)

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

主页面index.asp:

<%@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">

<title>聊天室</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.execute("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>

<form name="form1" method="post" action="" onSubmit="return false;">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<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="30" onChange="srcphone = this.value;"></select><br>

<span onClick="Load_room();" style="cursor:hand;">刷新房间列表</span><br>

<span onClick="Load_user();" style="cursor:hand;">刷新用户列表</span></div></td>

<td width="89%" valign="top"><textarea name="log" rows="35" wrap="VIRTUAL" id="log"></textarea></td>

</tr>

<tr>

<td>&nbsp;</td>

<td><input name="content" type="text" id="content" size="100" maxlength="140" onKeyDown="if (event.keyCode==13) {Send();}">

<input name="SendToServer" type="button" id="SendToServer" onClick="Send();" value="发送">

<input type="button" name="Submit" value="退出" onClick="window.location.href='logout.asp';"></td>

</tr>

</table>

</form>

</body>

</html>

非常关键的函数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("所有",0));

a = (new VBArray(room.Items())).toArray();

for (i in a)

{

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("所有人",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 Send()

{

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();

}

返回聊天内容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 rs=conn.execute("select top 50 * from chat_log where 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

%>

取得房间列表chat_room.asp:

<!--#include file="conn.asp"-->

<!--#include file="chklogin.asp"-->

<%

Response.Expires = -1

Response.ExpiresAbsolute = Now() - 1

Response.cachecontrol = "no-cache"

set rs=conn.execute("select * from chat_room order by id desc")

while not rs.eof

response.Write(escape( rs("id")&"*"&rs("roomname")&"#" ))

rs.movenext

wend

%>

负责取得在线用户chat_user.asp:

<!--#include file="conn.asp"-->

<!--#include file="chklogin.asp"-->

<%

Response.Expires = -1

Response.ExpiresAbsolute = Now() - 1

Response.cachecontrol = "no-cache"

set rs=conn.execute("select * from 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

%>

负责发送聊天内容chat_send.asp:

<!--#include file="conn.asp"-->

<!--#include file="chklogin.asp"-->

<%

'exec chat '13500000000','ME','278810','571','1'

phone=session("phone")

province=session("province")

content=Request("content")

srcphone=Request("srcphone")

conn.execute("exec chat '"&phone&"','"&content&"','"&srcphone&"','"&province&"','1'")

'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

%>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有