使用jQuery调用XML实现无刷新即时聊天
(编辑:jimmy 日期: 2024/11/20 浏览:3 次 )
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>使用JQuery调用XML实现无刷新即时聊天</title> <script src="/UploadFiles/2021-04-02/jquery-1.8.2.min.js">Chat.ashx:
<%@ WebHandler Language="C#" Class="Chat" %> using System; using System.Web; using System.Xml; public class Chat : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; string strContent = context.Request.QueryString["c"].ToString(); string strFromId = context.Request.QueryString["f"].ToString(); string strSendId = context.Request.QueryString["s"].ToString(); int intSuccess = 0; string strDate = DateTime.Now.ToString("HH:mm:ss"); XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(context.Server.MapPath("Chat.xml")); XmlNode root = xmlDoc.SelectSingleNode("chat"); XmlElement xmlE = xmlDoc.CreateElement("message"); xmlE.SetAttribute("fId", strFromId); xmlE.SetAttribute("sId", strSendId); XmlElement xmlEd = xmlDoc.CreateElement("datetime"); xmlEd.InnerText = strDate; xmlE.AppendChild(xmlEd); XmlElement xmlEc = xmlDoc.CreateElement("content"); xmlEc.InnerText = strContent; xmlE.AppendChild(xmlEc); root.AppendChild(xmlE); xmlDoc.Save(context.Server.MapPath("Chat.xml")); intSuccess = 1; } catch(Exception ex) { throw ex; } context.Response.Write(intSuccess); } public bool IsReusable { get { return false; } } }以上所述是小编给大家介绍的使用jQuery调用XML实现无刷新即时聊天,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言哦!
下一篇:JS中使用FormData上传文件、图片的方法