首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 网络编程-> Perl教程
无刷新聊天室(短信陪聊程序)-ASP教程,ASP应用
作者:网友供稿 点击:365
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
主页面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
%>


文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·无刷新聊天室(短信陪聊程序)-ASP教程,ASP应用
·C#中使用Excel-.NET教程,C#语言
·简要JAVA数据类型转换-JSP教程,Java技巧及代码
·Recordset对象方法详解-ASP教程,ASP应用
·选用和配置ups时应注意的几个问题
·新型无源元件的现状与发展
·用正则表达式解析C#文件(updated)-.NET教程,C#语言
·正则表达式大全-ASP教程,ASP应用
·VB与ActiveX控件签名谈-.NET教程,VB.Net语言
·IIS6 和Tomcat5 的整合-ASP教程,ASP应用
最新文章
·网上能免费赚钱?想要网上创业吗?_网赚技巧
·孙中伟:聚合文学网站资源的功能_站长访谈
·网站最令人讨厌的用户体验_站长心得
·设计理论:谈用户体验,别落下商业利益_站长心得
·经营个人网站需要脚踏实地_站长心得
·google adwords关键词广告须注意的7个问题_google推广
·网站提交google注册应注意的问题_google推广
·伦敦mecompany网站设计师谈网页布局艺术2_站长心得
·搜索引擎不收录页面的常见原因_seo网站优化
·搜索引擎注册九大秘法_站长心得
相关主题
  • 无刷新聊天室的技术实现-ASP教程,ASP应用
  • 无刷新聊天室技术实现方法(ASP相关)-PHP教程,PHP应用
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭