使用xml.而无须不断刷新*.asp.
无刷新实现发言的逐条显示.
使用application变量存储聊天记录,所以要需要建立一个虚拟目录
服务器端不需要支持xml,只要支持asp和能建立虚拟目录就可以了.
以下代码在nt4.0+iis4.0上通过.我估计在你的win2000下也差不多吧.
如果有问题,请多多赐教.netnice@chinaok.net
##########index.asp##############################
<html>
<head>
<title>蓝蝶聊天室 www.chinaok.net</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
body{font-size: 9pt}
td{font-size: 9pt}
.tbljm{border-bottom: #000000 1px solid; border-left: #000000 1px solid; border-right: #000000 1px solid; border-top: #000000 1px solid;color:#000000;}
</style>
<script language="javascript">
function openwin()
{winst="status=yes,scrollbars=yes,resizable=yes,width="+(screen.availwidth-10)+",height="+(screen.availheight-50)+",top=0,left=0";
window.open('about:blank','7923sdfsdfs',winst);
}
function form_onsubmit(obj)
{ var no=0,psd="1234567890";
if(obj.username.value==""){alert("请输入你的昵称!\n"); obj.username.focus(); return false;}
if(obj.username.value.indexof(" ")>-1 obj.username.value.indexof("'")>-1 obj.username.value.indexof("\"")>-1)
{alert("你的昵称含有非法字符!\n"); obj.username.focus(); return false;}
openwin();
return true;
}
</script>
</head>
<body bgcolor="#ffffff" text="#000000" valign="center" onload="javascript:document.form1.ok.blur()"
background="images/greystrip.gif">
<center><table border=0 width="67%">
<tbody>
<tr>
<td valign=center align="middle" style="font-size: 10.5pt"><font color=#0033ff>::::: :::::</font> </td>
</tr></tbody></table></center>
<table width="200" border="0" style="border-right: #003366 1px solid; border-top: #003366 1px solid; border-left:
#003366 1px solid; border-bottom: #003366 1px solid" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#304d7c" height="25">
<div align="center"><font color="#ffffff">用户登陆</font></div>
</td>
</tr>
<tr>
<td height="121">
<form name="form1" method="post" action="main.asp" onsubmit="return form_onsubmit(this)" target="7923sdfsdfs">
<table width="199" border="0" cellspacing="0" cellpadding="0" background="images/greystrip.gif">
<tr>
<td height="35">
<div align="center">用户名:
<input name="username" size="10" maxlength="20" class=tbljm>
</div>
</td>
</tr>
<tr>
<td height="41">
<div align="center">性 别:
<input type=radio value="0" name=sx checked>男 <input type="radio" value="1" name=sx>女
</div>
</td>
</tr>
<tr>
<td height="40">
<div align="center">
<input type="submit" name="ok" value="登 陆" class=tbljm>
<input type="reset" name="nook" value="重 写" class=tbljm><br><br><font color=red>
演示xmlhttp实现的无刷新技术<br>代码可下载</font><br></div>
</td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
<%response.buffer=true
response.expires=0
username=request.form("username")
if username="" then response.redirect "index.asp"
session("u_name")=username
if request.form("sx")="1" then
session("u_sx")="1"
else
session("u_sx")="0"
end if
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<link rel="shortcuticon" url="images/bluenote.ico">
<title>蓝蝶聊天室::欢迎您! www.chinaok.net .............蓝蝶精品网.............www.chinaok.net</title>
<style>
.fbd{border-bottom-color: #3a5c9f; border-bottom-style: solid; border-left-color: #3a5c9f; border-left-style: solid;
border-right-color: #3a5c9f; border-right-style: solid; border-top-color: #3a5c9f; border-top-style: solid}
.topc{bgcolor:#ffff00}
</style>
<script language="javascript">
self.onerror=null;
var nullframe = '<html><body bgcolor=#003366 text=#ffffff><center><h3 color=#ffffff>正在读取资料, 请稍候 ......</h3></center></body></html>';
</script>
</head>
<frameset cols="*,0" rows="*" class=topc>
<frameset rows="*,75" cols='*' framespacing="0" frameborder="1" border="0" >
<frameset rows="45%,*" cols='*' framespacing="1" border="1" name="content" frameborder='yes' class=topc>
<frame name="pub" src="javascript:parent.nullframe" scrolling="auto" frameborder=1 >
<frame name="my" src="javascript:parent.nullframe" scrolling="auto" frameborder=1>
</frameset>
<frame name="sd" scrolling="no" noresize src="send.asp" >
</frameset>
<noframes>
<p>此网页使用了框架,但您的浏览器不支持框架。</p>
</body>
</noframes>
</frameset>
</html>
<%'response.contenttype="text/xml"
response.write "<?xml version=""1.0"" encoding=""gb2312""?>"
response.write "<msg>"
dim c_info,c_lid,c_ip,u_lid,newlid,u_name,i
c_info=application("c_info")
u_lid=session("u_lid")
newlid=u_lid
u_name=".netnice"
for i=c_info(0)+6 to 240 step 6
if (c_info(i)>u_lid) and ((c_info(i+1)=u_name) or (c_info(i+2)=u_name) or (c_info(i+2)="大家") or (c_info(i+3)="0")) then
response.write c_info(i+5)
if (newlid<c_info(i)) then newlid=c_info(i)
end if
next
for i=1 to c_info(0) step 6
if (c_info(i)>u_lid) and ((c_info(i+1)=u_name) or (c_info(i+2)=u_name) or (c_info(i+2)="大家") or (c_info(i+3)="0")) then
response.write c_info(i+5)
if (newlid<c_info(i)) then newlid=c_info(i)
end if
next
response.write "</msg>"
session("u_lid")=newlid
%>
<% option explicit
dim f,t,sc,cl,e,w,sj
response.contenttype="text/xml"
f=request.form ("f")
t=request.form ("t")
sc=request.form ("sc")
cl=request.form ("cl")
e=request.form("e")
'w=request.form("w")
w="0"
'发言时间
sj=gettime()
if request.servervariables("request_method")="post" then
sc="<f>"&trim(f)&"</f><t>"&trim(t)&"</t><e>"&e&"</e><sc>"&trim(sc)&"<
/sc><cl>"
&trim(cl)&"</cl><sj>"&sj&"</sj>"
else
response.end
end if
dim c_info,c_lid,c_ip,u_lid,newlid,u_name,i
application.lock
c_info=application("c_info")
c_lid=application("c_lid")+1
application("c_lid")=c_lid
c_ip=(c_info(0)+6) mod 240
c_info(0)=c_ip
c_info(c_ip)=c_lid
c_info(c_ip+1)=f
c_info(c_ip+2)=t
c_info(c_ip+3)=w
c_info(c_ip+4)=""
c_info(c_ip+5)=sc '"<f>"&trim(f)&"</f><t>"&trim(t)&"</t><e>"&e&"</e><sc>"&trim(sc)&"<
;/sc><cl>"
&trim(cl)&"</cl><sj>"&sj&"</sj>"
application("c_info")=c_info
application.unlock
u_lid=session("u_lid")
newlid=u_lid
u_name=session("u_name")
'&application("c_lid")&"%"&c_info(0)
response.write "<?xml version=""1.0""?><msg>"
for i=c_info(0)+6 to 240 step 6
if (c_info(i)>u_lid) and ((c_info(i+1)=u_name) or (c_info(i+2)=u_name) or
(c_info(i+2)="大家") or (c_info(i+3)="0")) then
response.write c_info(i+5)
if (newlid<c_info(i)) then newlid=c_info(i)
end if
next
for i=1 to c_info(0) step 6
if (c_info(i)>u_lid) and ((c_info(i+1)=u_name) or (c_info(i+2)=u_name) or
(c_info(i+2)="大家") or (c_info(i+3)="0")) then
response.write c_info(i+5)
if (newlid<c_info(i)) then newlid=c_info(i)
end if
next
response.write "</msg>"
session("u_lid")=newlid
function gettime()
dim y,m,d,h,n,s
y=year(date())
m=month(date())
d=day(date())
h=hour(time())
n=minute(time())
s=second(time()) '当为是一位的 时候在前面加0
if len(m)=1 then m="0" & m
if len(d)=1 then d="0" & d
if len(h)=1 then h="0" & h
if len(n)=1 then n="0" & n
if len(s)=1 then s="0" & s
gettime=y&"/"&m&"/"&d &" " & h&":"& n&":"&s
end function%>
function bytes2bstr(vin)
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytes2bstr = strreturn
end function
</script>
<script language="javascript">
var me="<%=session("u_name")%>";
<%if session("u_sx")="1" then %>
var msx="girl.gif";
<%else%>
var msx="boy.gif";
<%end if%>
var ts=new os();
function os()
{this.f="";
this.t="";
this.e="";
this.w="0";
this.sc="";
this.cl="";
this.send=sendmsg;
}
function checksays()
{if (document.say.says.value=="") {alert("你要说什么呢?");return false;}
var fm=document.say;
var sc=fm.says.value;
var f=me
var t=fm.t.options[0].value;
var e=document.ot.userface.selectedindex;
var w="0"
var cl=fm.says.style.color;
fm.says.value="";
fm.says.focus();
ts.f=f;
ts.t=t;
ts.e=e;
ts.sc=sc;
ts.cl=cl;
ts.w=w;
settimeout("ts.send();",20);
delete(f);delete(sc);delete(fm);delete(cl);delete(t);delete(e);
return false;
}
function sendmsg()
{ if (this.t=="" && this.f=="") {alert("你要对谁说?");return;}
crld=1;
var ss="f="+code(this.f)+"&t="+code(this.t)+"&sc="+code(this.sc)+"&cl="+this.cl+"&e="+this.e;
ss=urlencoding(ss)
var osend=new activexobject("microsoft.xmlhttp");
osend.open("post","say.asp",false);
osend.setrequestheader("content-length",ss.length);
osend.setrequestheader("content-type","application/x-www-form-urlencoded");//没有这句就玩不转拉
osend.send(ss);
var odom=new activexobject("microsoft.xmldom");
odom.async=false;
body=bytes2bstr(osend.responsebody);
// alert(body);
odom.loadxml(body);
if(odom.parseerror.errorcode != 0)
{ alert(body);
alert("sorry.出现了错误");
return }
else
{var aryf=odom.documentelement.selectnodes("f");
var aryt=odom.documentelement.selectnodes("t");
var arysc=odom.documentelement.selectnodes("sc");
var arycl=odom.documentelement.selectnodes("cl");
var arysj=odom.documentelement.selectnodes("sj");
var arye=odom.documentelement.selectnodes("e");
var tmphtml="";
var img="";
lengt=aryf.length;
for(var i=0;i<lengt;i++){
img="<img src=boy.gif width=12 height=12 border=0>";
tmphtml="<font style=\'cursor:hand;color:"+arycl(i).text+"\'>"+document.ot.userface.options[arye(i).text].value+rp2(arysc(i).text,
"{^amp]","&")+"</font> <span class=t>["+arysj(i).text+"]</span><br>";
tmphtml=rp2(tmphtml,"$f","<a href=\"javascript:parent.sd.towho('"+aryf(i).text+"');\">"+img+aryf(i).text+"</a>");
tmphtml=rp2(tmphtml,"$t","<a href=\"javascript:parent.sd.towho('"+aryt(i).text+"');\">"+aryt(i).text+"</a>");
if (aryf(i).text==me aryt(i).text==me)
{ parent.my.ly.innerhtml+=tmphtml;
} else
parent.pub.ly.innerhtml+=tmphtml;
}// end for
}
delete(aryf);delete(aryt);delete(arysc);delete(arycl);delete(arysj);delete(arye);
delete(odom)
delete(osend)
delete(tmphtml)
}
function code(str)
{var a = new regexp("'","gi")
var b = new regexp("\"","gi")
str = str.replace(/&/gi,"&")
str = str.replace(/</gi,"<")
str = str.replace(/>/gi,">")
str = str.replace(b,""")
str = str.replace(/&/gi,"{^amp]")
delete(a)
delete(b)
return(str)
}
function rp2(str,fs,is)
{while (str.indexof(fs)!=-1)
str = str.replace(fs,is)
delete(a);
return(str)
}
var ordom=new activexobject("microsoft.xmldom");
ordom.async=false;
var path="reload.asp";
var tcok;
function clock()
{crld++;
if (crld>10){crld=1;getxmldata();}
cleartimeout(tcok);
tcok=settimeout("clock()",1000);
}
function getxmldata() //这就是刷新用户xml数据的函数
{crld=1;
ordom.load(path)
if(ordom.parseerror.errorcode != 0)
{alert("sorry.出现了错误");
return }
else
{
var aryf=ordom.documentelement.selectnodes("f");
var aryt=ordom.documentelement.selectnodes("t");
var arysc=ordom.documentelement.selectnodes("sc");
var arycl=ordom.documentelement.selectnodes("cl");
var arysj=ordom.documentelement.selectnodes("sj");
var arye=ordom.documentelement.selectnodes("e");
var tmphtml="";
lengt=aryf.length;
for(var i=0;i<lengt;i++){
img="<img src=girl.gif width=12 height=12 border=0>";
tmphtml="<font style=\'cursor:hand;color:"+arycl(i).text+"\'>"+ev[arye(i).text*2]+rp2(arysc(i).text,"{^amp]","&")+"</font> <span class=t>["+arysj(i).text+"]</span><br>";
tmphtml=rp2(tmphtml,"$f","<a href=\"javascript:parent.sd.towho('"+aryf(i).text+"');\">"+img+aryf(i).text+"</a>");
tmphtml=rp2(tmphtml,"$t","<a href=\"javascript:parent.sd.towho('"+aryt(i).text+"');\">"+aryt(i).text+"</a>");
if (aryf(i).text==me aryt(i).text==me)
{ parent.my.ly.innerhtml+=tmphtml;
} else
parent.pub.ly.innerhtml+=tmphtml;
}
}
delete(aryf);delete(aryt);delete(arysc);delete(arycl);delete(arysj);
}
function towho(un){
document.say.t.options[0].value=un;
document.say.t.options[0].text=un;
document.say.says.focus();return;}
</script>
<base onmouseover="parent.window.status='欢迎光临 蓝蝶精品网 www.chinaok.net 站长.netnice qicq:6097356 ';return true;">
</head>
<body bgcolor="#76b4d9" topmargin="4" leftmargin="1" >
<table border="0" width="767" cellspacing="0" cellpadding="0" >
<tr><td width="735" height="16" align="left" nowrap>
<form method="post" action="save.asp" name="say" target="b" onsubmit='return(checksays());'>
<input type="hidden" name="oldsays" >
<input name="f" maxlength="10" size="10" value="<%=session("u_name")%>" readonly style="background-color: #76aadd; border-bottom: 0px double; border-left: 0px double; border-right: 0px double; border-top: 0px double; color: #ffffff; text-align: right">
对 <select name="t" onclick="this.options[0].value='大家'; document.say.t.options[0].text='大家'; document.say.says.focus();" >
<option value="大家" selected>大家</option>
</select> 说:<input type=text name="says" maxlength="150" size="50" style="background-color: #ffffff; border-bottom: 1px double; border-left: 1px double; border-right: 1px double; border-top: 1px double; color: #000000" accesskey="t" title="发表对话区(alt+t)可激活!" language="javascript ">
<input type="submit" name="send" value="发言" class="an" accesskey="s" onmouseover="this.style.color='3366dd'" onmouseout="this.style.color='663300'" title="(alt+s)">
</form></td></tr></table>
<div style="height: 80px; left: 15px; position: absolute; top: 30px; width: 600px">
<form name="ot">
<table border="0" width="600" cellspacing="0" cellpadding="0">
<tr>
<td width="160" height="16" align="center" nowrap valign="top">
<input accesskey="a" type="checkbox" name="as" checked onclick="parent.pub.scrollit();parent.my.scrollit();document.say.says.focus();"><a onclick=moveself(); title=" “激活/禁止”对话区自动滚屏(alt+a)!">滚屏</a>
</td>
<td width="230" height="16" align="left" nowrap valign="top"> <span title=" 改变你的发言的字体颜色(alt+f)!">
<select name=usercolor accesskey="f" onchange="document.say.says.style.color=this.options[this.selectedindex].value;">
<option selected style="color: #000000" value="000000">默认颜色</option>
<option style="color: #000000" value="#000000">黑色沉静</option>
<option style="color: #ff0000" value='#ff0000'>红色热情</option>
<option style="color: #0000ff" value='#0000ff'>蓝色开朗</option>
<option style="color: #ff00ff" value='#ff00ff'>桃色浪漫</option>
<option style="color: #009900" value='#009900'>绿色青春</option>
<option style="color: #009999" value='#009999'>青色清爽</option>
<option style="color: #990099" value='#990099'>紫色拘谨</option>
<option style="color: #990000" value='#990000'>暗夜兴奋</option>
<option style="color: #000099" value='#000099'>深蓝忧郁</option>
<option style="color: #999900" value='#999900'>卡其制服</option>
<option style="color: #ff9900" value='#ff9900'>镏金岁月</option>
<option style="color: #0099ff" value='#0099ff'>湖波荡漾</option>
<option style="color: #9900ff" value='#9900ff'>发亮蓝紫</option>
<option style="color: #ff0099" value='#ff0099'>爱的暗示</option>
<option style="color: #006600" value='#006600'>墨绿深沉</option>
<option style="color: #333333" value='#333333'>灰色轨迹</option>
<option style="color: #999999" value='#999999'>伦敦灰雾</option>
</select></span>
<span title=" 改变您的说话时的表情(alt+q)!" ><select accesskey="q" name=userface style="font-size: 9pt;width:65px" size="1">
<script language="javascript">
for(var if=0;if<ev.length;if+=2)
{document.writeln("<option value=\""+ev[if]+"\">"+ev[if+1]);
}
</script>
</select></span> <input type="checkbox" name="ws" id="ws" accesskey="m" ><a title=" 和聊友说句悄悄话(alt+m)!"><label for=ws >私聊</label></a> </td>
<td width="250" height="16" align="left" nowrap valign="top">
<input id=clock name=clock type=button value=1200 class="an" title="如果您长时间不发言(潜水),请注意:当计数器减至零时,您将被被踢出!" style="color:#ff3300;width:60;" disabled>
</td>
</tr>
</table> </form>
</div>
<script>
write();
getxmldata();
clock();
</script>
</body>
</html>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器