Use jQuery to call XML for instant chat without refreshing, jqueryxml

Source: Internet
Author: User

Use jQuery to call XML for instant chat without refreshing, jqueryxml

HTML:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

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;}}}

The above section describes how to use jQuery to call XML for instant chat without refreshing. I hope it will be helpful to you. If you have any questions, please leave a message!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.