先简单说明下
服务端
用程序生成需要的 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.createEleme