高分悬赏,请各位给点儿意见……

mardonma 2010-07-23 04:04:14
我在做一个交友网站,里面有个在线聊天模块。
这个模块功能大概是这样的:
①登录后的会员选择和其他会员聊天,在新页面的文本域中输入聊天内容,“发送”后,信息存入数据库。
②如果接收者在线,则马上会有相应的消息提示,点击可以查看消息,并可以选择回复等操作。如果不在线,则在下次登录时看到消息提示……
第一步,很简单,已经做好了。关键是第二步,不管浏览者在哪个页面都能看到有消息提示。这个消息提示该用什么呀的方式呢?关键的地方,就是局部刷新:当有人发送了消息时,马上会有提示,也就是说要定时刷新。。
总之,第二步我现在搞不定,没有思路。请大虾们指点。最好能具体一些,谢谢了!(我是用Asp+VbScript SQL Server 2005 做的)
...全文
176 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
mfdipq 2010-07-31
  • 打赏
  • 举报
回复
学习~~~~~~~~
xcgh 2010-07-31
  • 打赏
  • 举报
回复
给你个推技术代码,自己搞定,见笑,没经过大批量测试,可以共同研究
<script language="javascript1.2" src="./inc/prototype.js"></script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr class="beijing1">
<td height="31" class="leftzi1" align="center"><button style='cursor:hand;MARGIN-LEFT:2px;width:204px;height:25px;font-size:12px;border:1px solid #A4B3C8;background-color:#E5E3E4;' type="button" onclick="javascript:openWindowCenter3('./lookAllNews.asp',500,400)"><span id="MsgNum"></span></button></td>
</tr>
</table><script language="javascript1.2" src="./inc/acceptMsg.js"></script>
acceptMsg.js文件内容
var Comet = Class.create();
Comet.prototype = {

timestamp: 0,
url: './pushMsgNews.asp',
noerror: true,

initialize: function() { },

connect: function()
{
this.ajax = new Ajax.Request(this.url, {
method: 'get',
parameters: { 'timestamp' : this.timestamp },
onSuccess: function(transport) {
// handle the server response
var response = transport.responseText.evalJSON();
this.comet.timestamp = response['timestamp'];
this.comet.handleResponse(response);
this.comet.noerror = true;
},
onComplete: function(transport) {
// send a new ajax request when this request is finished
if (!this.comet.noerror)
// if a connection problem occurs, try to reconnect each 5 seconds
setTimeout(function(){ comet.connect() }, 5000);
else
this.comet.connect();
this.comet.noerror = false;
}
});
this.ajax.comet = this;
},

disconnect: function()
{
},

handleResponse: function(response)
{
$('MsgNum').innerHTML = response['msg'];
},

doRequest: function(request)
{
new Ajax.Request(this.url, {
method: 'get',
parameters: { 'msg' : request }
});
}
}
var comet = new Comet();
comet.connect();
pushMsgNews.asp文件
<%@ Language = "VBScript" codepage = "936" %>
<!--#include file="CheckLogin.asp" -->
<!--#include FILE="./inc/conn.asp"-->
<!--#include FILE="./inc/funcdb.asp"-->
<!--#include FILE="./inc/JSON.asp"-->
<%
Response.Charset="gb2312"
'@ EnableSessionState = False'指令关闭网页会话跟踪
Response.Buffer = true'当页面输出时间比较长时,先把输出的内容先放到缓存里面,获取或设置一个值,该值指示是否缓冲输出,并在完成处理整个响应之后将其发送。
table_name = "t_message"
'接收信息存库
If(trim(request.form("message"))<> "") Then
Redim fieldarr(0)
fieldarr(0) = (new JSON).toJSON("senduser", session("UserName"), true)
indb table_name, fieldarr, "|btnSave|btnReset|"
response.end
End If

'当前id
receiveTime = Now()

'currentId = return_one("SELECT @@IDENTITY AS ID", 0)
currentId = return_one("SELECT max(id) from "&table_name&" where username = '"& session("UserName") &"' and ifread = '0'", 0)

If(Not IsNumeric(Trim(currentId))) Then
currentId = 0
End If
'多少条消息
msgNum = return_one("SELECT count(id) from "&table_name&" where username = '"& session("UserName") &"' and ifread = '0'", 0)
sql = "select * from "&table_name&" where (username = '"& session("UserName") &"' or senduser = '"& session("UserName") &"') and id = "& currentId &" and ifread = '0' order by d_time desc"
'Response.Write sql
set rs = server.Createobject("adodb.Recordset")
rs.Open sql,conn,1,1
If(not rs.eof) Then
'暂停程序
Do While datediff("s", rs("d_time"), receiveTime)> 1
Call delaySec(1)
'Response.ExpiresAbsolute = Now()- 1'这一句就是在上面放在缓存里面的内容显示完毕后,就将缓存立即过期,等于清空
'Response.Expires = 0'设置缓存过期,写在页面的最上端,后面跟的是一个时间,就是过期的时间,0表示立即过期。
'Response.CacheControl = "no-cache"
'Response.AddHeader "Pragma", "No-Cache"
receiveTime = rs("d_time")
conn.Execute("update "&table_name&" set ifread='1' where username = '"& session("UserName") &"' and ifread='0'")
Loop

'发送信息
If(Response.IsClientConnected) Then
'================================
'在这里修改或自定义要执行的ASP代码
msgStructure = (new JSON).toJSON("", rs, true)'json的字符串格式不一样,所以用了替换
msgStructure = Replace(msgStructure, """"": ", "")
msgStructure = Replace(msgStructure, "[", "")
msgStructure = Replace(msgStructure, "]", "")
Response.Write msgStructure
'================================
Response.Flush
Response.Clear
End If
Else
data_close()
response.end
End if
data_close()
%>
sire168 2010-07-30
  • 打赏
  • 举报
回复
用Ajax会容易实现点!试试吧
weizewang 2010-07-30
  • 打赏
  • 举报
回复
用AJAX,不会就用ifram这个占资源点
zhang1struts1yun 2010-07-30
  • 打赏
  • 举报
回复
baidu一下,什么都有
SNOYC 2010-07-24
  • 打赏
  • 举报
回复
想在各个页面都可以看到,那我建议你使用框架

你想定时刷新建议你使用AJAX定时取信息,用AJAX的好处是可以保证页面不刷新也能获取到新的数据
薪水 2010-07-24
  • 打赏
  • 举报
回复
BD。。。
mardonma 2010-07-24
  • 打赏
  • 举报
回复
能不能给个完整的定时从服务器数据库提取信息的例子啊????
  • 打赏
  • 举报
回复
很简单的
就是一个对象的问题
你google搜索一下ajax,例子多得是
mardonma 2010-07-24
  • 打赏
  • 举报
回复
我之前一直没有学习过Ajax,有关于这个功能大概的代码或者算法不,发个我学习学习。
KylinBL 2010-07-24
  • 打赏
  • 举报
回复
学习~
叫我梁大侠 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 snoyc 的回复:]
想在各个页面都可以看到,那我建议你使用框架

你想定时刷新建议你使用AJAX定时取信息,用AJAX的好处是可以保证页面不刷新也能获取到新的数据
[/Quote]
学习下
001007009 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 falizixun2 的回复:]
用AJAX吧,其他方法在界面上不好控制!
[/Quote]


支持
huanglongqi1314 2010-07-24
  • 打赏
  • 举报
回复
建议用ajax
kaifadi 2010-07-24
  • 打赏
  • 举报
回复
用AJAX吧,其他方法在界面上不好控制!
yqzhao_sx 2010-07-24
  • 打赏
  • 举报
回复
<iframe ></iframe>
  • 打赏
  • 举报
回复
做一个信息检查页,里面用AJAX定时去检查有无新信息.
然后在所有页面包含这个页面.
竹林听雨2005 2010-07-23
  • 打赏
  • 举报
回复
他那里好象是使用了右下角弹出窗口方式,类似WINDOWS系统里的一些消息提醒一样的,

你可以登陆佳缘网,注册个号然后看看效果。

http://www.jiayuan.com

同类网站,或许对你的设计有帮助。
竹林听雨2005 2010-07-23
  • 打赏
  • 举报
回复
前段时间朋友上佳缘网,好象就是使用你这样的思路。

可能做了一个页面,这里去查询别人发送的信息了,然后每个页面include调用,

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧