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

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

服务端

用程序生成需要的 xml 文件

客户端

利用 xmlhttp 或者 dso(注意状态) 定时刷新需要的数据

相对来说 dso 可以映射成 recordset 操作比较简单

以下是我简单写着玩的东西 不是完整部分 而且十分简陋

只是代码片段 但作为技术参考已经足够

需要 msxml 4.0

服务端 我写了两个构造函数 分别是 聊天内容 聊天用户


<script language="jscript" runat="server">
function slightboychat()
{

this.id;
this.xmldomelement = server.createobject("msxml2.freethreadeddomdocument.4.0")

this.add = function(name, content, append)
{
var root = this.xmldomelement.documentelement;
var newitem = this.xmldomelement.createelement("item");
var newitemname = this.xmldomelement.createelement("name");
var newitemnamevalue = this.xmldomelement.createcdatasection(name);
newitemname.appendchild(newitemnamevalue)
var newitemcontent = this.xmldomelement.createelement("content");
var newitemcontentvalue = this.xmldomelement.createcdatasection(content);
newitemcontent.appendchild(newitemcontentvalue)
var newitemappend = this.xmldomelement.createelement("append");
newitemappend.text = append;
newitem.appendchild(newitemname);
newitem.appendchild(newitemcontent);
newitem.appendchild(newitemappend);
if ( root.childnodes.length > 10 )
{
root.removechild(root.firstchild)
}
root.appendchild(newitem)
}
this.save = function()
{
application("chatcontent") = this.xmldomelement.xml;
}
this.guid = function(pushguid)
{
if ( pushguid.count > 0 )
{
this.id = pushguid;
}
else
{
this.id = "";
}
}
this.xml = function()
{
if ( this.id != "" )
{
var xmldomelementstring = "<?xml version=\"1.0\" encoding=\"gb2312\"?><chat>";
var items = chat.xmldomelement.selectnodes("//item[append > "+ this.id +"]")
for (var item = items.nextnode(); item; item = items.nextnode())
{
xmldomelementstring += item.xml;
}
xmldomelementstring += "</chat>";
if ( items.length > 0 )
{
return xmldomelementstring;
}
else
{
return;
}
}
else
{
return this.xmldomelement.xml.replace("<?xml version=\"1.0\"?>","<?xml version=\"1.0\" encoding=\"gb2312\"?>");
}

}
this.load = function()
{
if ( application("chatcontent") == "" | typeof(application("chatcontent")) == "undefined" )
{
application("chatcontent") = "<?xml version=\"1.0\" encoding=\"gb2312\"?><chat><item><name>slightboy</name><content>欢迎 ^^</content><append>"+ new date().gettime() +"</append></item></chat>";
}
this.xmldomelement.loadxml(application("chatcontent"));

}
this.empty = function()
{
application("chatcontent") = "<?xml version=\"1.0\" encoding=\"gb2312\"?><chat><item><name>slightboy</name><content>欢迎 ^^</content><append>"+ new date().gettime() +"</append></item></chat>";
}

this.load();
}


function slightboychatlist()
{
this.xmldomelement = server.createobject("msxml2.freethreadeddomdocument.4.0")

this.add = function(name, level)
{
var root = this.xmldomelement.documentelement;
var newitem = this.xmldomelement.createelement("item");
var newitemname = this.xmldomelement.createelement("name");
var newitemnamevalue = this.xmldomelement.createcdatasection(name);
newitemname.appendchild(newitemnamevalue)
var newitemlevel = this.xmldomelement.createelement("level");
var newitemlevelvalue = this.xmldomelement.createcdatasection(level);
newitemlevel.appendchild(newitemlevelvalue)
var newitemappend = this.xmldomelement.createelement("append");
newitemappend.text = append;
newitem.appendchild(newitemname);
newitem.appendchild(newitemlevel);
root.appendchild(newitem)
}
this.save = function()
{
application("chatuser") = this.xmldomelement.xml;
}
this.xml = function()
{
return this.xmldomelement.xml.replace("<?xml version=\"1.0\"?>","<?xml version=\"1.0\" encoding=\"gb2312\"?>");
}
this.load = function()
{
if ( application("chatuser") == "" | typeof(application("chatuser")) == "undefined" )
{
application("chatcontent") = "<?xml version=\"1.0\" encoding=\"gb2312\"?><chat></chat>";
}
this.xmldomelement.loadxml(application("chatuser"));

}
this.remove = function()
{
var removetimer = new date().gettime();
removetimer -= 300000;
var root = this.xmldomelement.documentelement;
var removenodes = root.selectnodes("//item[append < "+ removetimer +"]");
while (removenodes.peeknode() != null)
{
removenodes.removenext();
}
}
this.load();
}
</script>


客户端聊天内容显示页面


<html>
<meta http-equiv=content-type content=text/html; charset=gb2312>
<script language="javascript">
function slightboychat()
{
this.guid = "";
this.recordset;
var timer = new date();
this.checkstate = function()
{
if ( xmlchat.readystate == "complete" )
{
this.recordset = xmlchat.recordset;
this.item();
}
}
this.item = function()
{
try
{
var pushstring;

this.recordset.movelast();
if ( this.recordset("append").value != this.guid)
{
this.guid = this.recordset("append").value;
}
else
{
this.recordset = null;
return;
}
this.recordset.movefirst();
while (!this.recordset.eof)
{

timer.settime(this.recordset("append").value)
pushstring = this.recordset("name").value +" 说: "+ this.recordset("content").value +" <small>"+ timer.tolocalestring() +"</small>";
this.push(pushstring);
this.recordset.movenext();
}
this.recordset = null;
}
catch(e)
{
return;
}


}

this.push = function(pushstring)
{
var chatitem = document.createelement("li");
chatitem.innerhtml = pushstring;
chatlist.insertadjacentelement("afterbegin",chatitem);
}
this.load = function()
{
xmlchat.src = "background.asp?guid="+ this.guid;
}
this.remove = function()
{
try
{
var removelength = chatlist.children.length;
for (var i = 0; i < removelength; i++)
{
chatlist.removechild(chatlist.children(0));
}
}
catch(e)
{
}
}
}


var chat = new slightboychat();
window.setinterval("chat.load()", 5000);
</script>
</head>

<body>
<xml id="xmlchat" src="background.asp" onreadystatechange="chat.checkstate()"></xml>
<ul id="chatlist" style="list-style: none;margin: 0px;">
<li>欢迎访问 slightboy xml chatroom...<small>(slightboy)</small></li>
</ul>
</body>
</html>



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

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·VB 二进制,八进制,十进制,十六进制转换-.NET教程,VB.Net语言
·以实例说明如何使用C#从数据库中提取数据,按要求自动生成定制的Excel表格-.NET教程,C#语言
·一个登陆窗口的记数判断登录(有用哦),了解"IF"语句的用应-ASP教程,数据库相关
·asp.net无法调试的解决方法-ASP教程,ASP应用
·C#多线程共享数据-.NET教程,C#语言
·在ASP中连接数据库(连接字符串)-ASP教程,数据库相关
·web应用分页技术-JSP教程,资料/其它
·虚拟主机上asp.net运行权限不足问题及解决-.NET教程,Asp.Net开发
·生成随机字符串-.NET教程,评论及其它
·阀控式铅酸蓄电池的维护
最新文章
·链接的12种类型和获取方法_营销推广
·fireworks绘制简洁精致的rss图标_fireworks教程
·公布如何判断adsense无效点击的隐忧_网赚技巧
·企业网站制定搜索引擎优化策略的方案_站长心得
·论坛有感:一个人做,真的很难_站长心得
·制作行业网站时所需考虑的一些问题_站长心得
·在xp下享受windows vista屏保待遇_windows xp
·个人博客如何实现自己的商业价值?_站长心得
·分析网页的关键字密度与网站排名_站长心得
·首页设计所应该达到的几个设计1_站长心得
相关主题
  • 无刷新聊天室(短信陪聊程序)-ASP教程,ASP应用
  • 无刷新聊天室技术实现方法(ASP相关)-PHP教程,PHP应用
  • 西部数码虚拟主机

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