fairy 2007-6-17 00:43
XMLHTTP+javascript+Asp写得聊天室,无刷新实现
[code]
<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>
[/code]
fairy 2007-6-17 00:44
[code]<%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>[/code]
fairy 2007-6-17 00:45
[code]<%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
%>
[/code]
fairy 2007-6-17 00:46
[code]<% 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%>
[/code]