HTML:
!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN ' ' http://www .w3。org/TR/XHTML 1/DTD/XHTML 1-Transitional。DTD ' html xmlns=' http://www .w3。org/1999/XHTML '标题使用JQuery调用可扩展置标语言实现无刷新即时聊天/title脚本src=' http : jscript/jquery-1。8 .2 .量滴js ' type=' text/JavaScript '/script style type=' text/CSS ' body { font-size :13 px } H3 { padd :0 px;margin:8px 0px} .iframe { width :260 pxborder :固体1px #666} .iframe .标题{ padding:5px背景-color:#eee} .iframe .标题SPNId { font-weight : bold;font-family:Arial} .iframe .内容{ padd :8 pxfont-size :12 px;}.iframe .内容lst { height :180 pxborder :固体1px # cccpadding:3px线高:1.5 em溢出-:亿欧元;}.iframe .内容nav{ color:#006EE} .iframe .内容。导航。时间iframe .内容msg{ margin-left:5px} .iframe .内容txt { height:50px宽度宽度:238 pxborder : solid 1px # CCC } .btn {border:#666 1px固体;padding:2px宽度:80 px过滤器: progid : maximagettransform .微软。渐变(渐变类型=0,StartColorStr=# ffffff,endcolorst=# ece9d 8);}/style脚本类型=' text/JavaScript ' $(function(){ var $ FormId=1243242;var $ SendID=1234560 $(' # Spnsendid ').html($ SendID);setTimeout(showList($FormId,$SendId),3000);$('#btnSend ').单击(函数(){$).ajax({url: 'Chat.ashx?s=' $ SendID ' f=' $ FormId ' c=' TxtA。值,成功:函数(数据){if(数据==1) {showList($FormId,$ SendID);txta . value=} } });});函数显示列表(f,s) {$ .ajax({url: 'Chat.xml ',dataType: 'xml ',成功:函数(数据){var $strUser=$(数据)。查找('消息');var strHTML=$ StrUSer。每个(函数(){ if($(this)).attr('fId')==f $(这个)。attr(' SiD ')===s)| |($(this).attr('fId')==s $(这个)。attr(' SiD '==f)){ var STrnav=$(this).attr(' FId ');if (strNav==f) {strNav='我说;} STRHtml=' div class= ' nav ' span(' STrnav ')/span span class= ' time ' $(this).子代(“日期时间”).text()' /span /div ';strHtml=' div class= ' msg ' $(this).子代(“内容”).text()' /div ';}});//显示处理后的数据$('#chatList ').html(STRHtml);}});} })/script/head dydiv class=' iframe ' div class=' title '德仔即时聊天与(span id=' spnSendid ' class=' spNId '/span)聊天中/div class=' content ' div id=' ChatList ' class=' lst '/div/div class=' content '文本区域id=' TxTa ' class=' TxT '/文本区域输入id=' Btnsend ' type=' button ' value='发送class=' BTN '/div/div/body/HTMlChat。ashx :
"%@"网络处理程序语言="c# "类="使用系统聊天";使用系统网络.使用系统Xml .公共类chat : IHttpHandler { public void process request(HttpContext上下文){ context .响应。内容类型='文本/纯文本;字符串strContent=context .请求。查询字符串['c'].ToString();字符串strFromId=上下文.请求。查询字符串['f'].ToString();字符串strSendId=上下文.请求。查询字符串[']。ToString();int IntSuccess=0;字符串日期=日期时间.现在。ToString(' hh :mm :s ');XmlDocument XMldoc=new XMldocument();请尝试{xmlDoc .加载(上下文服务器。地图路径('聊天。XML ');XmlNode根=xmlDoc .选择单个节点("聊天");XmlElement xmlE=xmlDoc .创建元素(“消息”);xmlE .SetAttribute('fId ',strromid);xmlE .SetAttribute('sId ',StrSeDidXmlElement xmlEd=xmlDoc .创建元素(' datetime ');xmlEd .InnerText=strDatexmlE .AppendChild(XMled);XmlElement xmlEc=xmlDoc .创建元素(“内容”);xmlEc .InnerText=strContentxmlE .AppendChild(xmlEc);根AppendChild(XMle);xmlDoc .保存(上下文服务器。地图路径('聊天。XML ');int success=1;} catch(Exception ex){ throw ex;}上下文。回应。写(intSuccess);} public bool IsReuse { get { return false;} } }
以上所述是小编给大家介绍的使用jQuery调用可扩展置标语言实现无刷新即时聊天,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言哦!