<%@ WebHandler Language="C#" Class="read" %> using System; using System.Web; using DBHelper; using MySql.Data.MySqlClient; using System.Web.SessionState; public class read : IHttpHandler, IReadOnlySessionState { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; string sql = "select * from t_current_chat where client_guid= @client_guid"; MySqlParameter[] pa = new MySqlParameter[] { new MySqlParameter("@client_guid", context.Session["guid"]) }; MySqlDataReader dr = SqlHelper.ExecuteReaderText(sql, pa); System.Text.StringBuilder buf = new System.Text.StringBuilder("{"); buf.Append(""comments":["); string names = ""; while (dr.Read()) { // names += "{"client_guid":"" + dr["client_guid"].ToString() + """ + ","send_time":"" + dr["send_time"] + """ + ","chat_content":"" + dr["chat_content"].ToString() + ""},"; names += "{"client_guid":"" + dr["client_guid"].ToString() + """ + ","send_time":"" + dr["send_time"].ToString() + """ + ","chat_content":"" + dr["chat_content"].ToString().Trim() + ""},"; } if (names != "") { names = names.Substring(0, names.Length - 1); } buf.Append(names); buf.Append("]}"); context.Response.Write(buf.ToString()); } public bool IsReusable { get { return false; } } }