整个程序是无刷新聊天室,还没有做完呢,看见有人能用上就放上来了,希望楼主能用的上。呵呵
chat_user.asp代码:
<!--#include file="conn.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("userid")&"*"&rs("nickname")&"#" ))
rs.movenext
wend
%>
chat_room.asp代码:
<!--#include file="conn.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_log.asp代码:
<!--#include file="conn.asp"-->
<%
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.cachecontrol = "no-cache"
set rs=conn.execute("select top 10 * 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
%>
还没完成呢,可以看看,呵呵
<%@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"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<title>聊天室</title>
</head>
<body>
<script language="javascript">
var room,log,user,myroomid=0,pid;
log =Array();
<%
set rs=conn.execute("select top 1 chat_id as id from chat_log where chat_id in (select top 5 chat_id from chat_log order by chat_id desc) order by chat_id")
response.Write("pid="&rs("id")&";")
%>
window.onload=function init()
{
Load_log();
Load_user();
Load_room();
setTimeout("Load_log();",5000);
//setTimeout("Load_room();",60000);
//setTimeout("Load_user();",60000);
}
function GetPage(url)
{
var xml = new ActiveXObject("Microsoft.XMLHTTP");
xml.open("GET",url,false);
xml.send();
return unescape(xml.ResponseText);
}
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();
}
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,temp;
user = new ActiveXObject("Scripting.Dictionary");
var i=str.length-1;
while(i-- >0)
{
temp = str[i].split("*");
userid = temp[0];
nickname = temp[1];
user.Add(userid,nickname);
}
Show_user();
}
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("所有人",0));
a = (new VBArray(user.Items())).toArray();
for (i in a)
{
document.form1.chat_user.options.add(new Option(a[i],i));
}
document.form1.chat_user.selectedIndex = myroomid;
}
function Load_log()
{
var value=GetPage("chat_log.asp?id="+pid);
var str = value.split("#");
alert(pid);
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;
}
Show_log();
}
function Show_log()
{
var i=log.length-1;
var str;
str="";
while(i>=0)
{
if (log[i-1]==myroomid || myroomid==0)
{
str += log[i].toString() + "\n";
}
i -=2;
}
document.form1.content.value = str;
}
</script>
<form name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><select id="chat_room" onChange="myroomid=document.form1.chat_room.selectedIndex;" style="width:100px;"></select><br><select id="chat_user" name="select" size="30" style="width:100px;">
</select></td>
<td valign="top"><textarea name="content" cols="120" rows="35" wrap="VIRTUAL" id="content"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="textfield" type="text" size="100">
<input type="submit" name="Submit" value="发送"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>