具体内容:一个网上招生系统,需要一个在线客服系统,类似: http://www.niit.com.cn/    就是网页加载之后会弹窗询问是否进行咨询,可选择稍后咨询。   如果选择进行咨询则打开一个聊天窗口,与服务端进行即时聊天咨询,选择稍后则取消。   貌似不能上截图,不知道描述清楚了没有,嗯嗯,其实就是一个简单的通信系统,一般的教育站都有,例如Live’800。
 
   但是都是要收费的,项目需求低,希望自己做一个!所以求具体思路!先谢了。
   

解决方案 »

  1.   

    想当然的认为:启动加载DIV 咨询→聊天 取消→关闭DIV
      

  2.   

    在application 中创建 一个对象 主要包括一个内存表和几个方法,用来向内存表中插入和查询的。
    客户端写几个ajax页就行了。以下的我的类代码你参考下吧。
        public class TheGlobalMsgs
        {
            const long timerDelay = 60000;//定时器过期时间60秒(1分钟内的短消息保留),客户端最长每30秒一取!        Timer theTimer;
            public static DataTable theMsgsTable = null;
            public TheGlobalMsgs()
            {
                theMsgsTable = new DataTable("TheMsgTable");        //|    建立表, 表名:"Msgs"
                System.Data.DataColumn Column1 = new DataColumn("id", typeof(System.Int64)); //|    建立字段, 字段名:"id", 类型: int
                System.Data.DataColumn Column2 = new DataColumn("msgText", typeof(System.String));
                System.Data.DataColumn Column3 = new DataColumn("GetUserID", typeof(System.String));
                System.Data.DataColumn Column4 = new DataColumn("SendUserID", typeof(System.String));
                System.Data.DataColumn Column5 = new DataColumn("SendUserName", typeof(System.String));
                System.Data.DataColumn Column6 = new DataColumn("SendTime", typeof(System.DateTime));            Column1.AutoIncrement = true;    //| 设置自增ID
                Column1.AutoIncrementSeed = 1;    //|    ID 起始值
                Column1.AutoIncrementStep = 1;    //|    递增量            theMsgsTable.Columns.Add(Column1);
                theMsgsTable.Columns.Add(Column2);
                theMsgsTable.Columns.Add(Column3);
                theMsgsTable.Columns.Add(Column4);
                theMsgsTable.Columns.Add(Column5);
                theMsgsTable.Columns.Add(Column6);
                //我想在内存中动态创建一个表 
                //    找到这么一段代码 请高手如何创建一个完整的表 包括创建字段,设置主键,设置字段类型 等等
                theMsgsTable.PrimaryKey = new System.Data.DataColumn[] { Column1 };            TimerCallback OnTimerTick = new TimerCallback(TimerTick);
                theTimer = new Timer(OnTimerTick, null, timerDelay, timerDelay);        }        /// <summary>
            /// 定时期过期方法 删除表中的两分钟以前的过期值
            /// </summary>
            /// <param name="state"></param>
            private void TimerTick(object state)
            {
                DataView theDV = new DataView(theMsgsTable);
                theDV.AllowDelete = true;
                theDV.AllowEdit = true;
                theDV.AllowNew = true;
                theDV.RowFilter = "SendTime < #" + DateTime.Now.AddMilliseconds(-120000).ToLongTimeString() + "#" ;
                for (int i = 0; i < theDV.Count; i++)
                {
                    theDV.Delete(i);
                }
                theMsgsTable.AcceptChanges();
            }        /// <summary>
            /// 向内存表中添加一个消息
            /// </summary>
            /// <param name="inp_SendUser_ID"></param>
            /// <param name="inp_SendUser_Name"></param>
            /// <param name="inp_GetUser_ID"></param>
            /// <param name="inp_TheMsgText"></param>
            /// <returns></returns>
            public bool AddMsg(string inp_SendUser_ID, string inp_SendUser_Name, string inp_GetUser_ID, string inp_TheMsgText)
            {
                if (inp_GetUser_ID == null || inp_GetUser_ID == "" || !DAL.DBBase.IsInt(inp_GetUser_ID) || inp_TheMsgText == null || inp_TheMsgText == "")
                {
                    return false;
                }
                if (inp_SendUser_ID != null && inp_SendUser_ID != "")
                {
                    if (!DAL.DBBase.IsInt(inp_SendUser_ID))
                    {
                        return false;
                    }
                }            System.Data.DataRow theRow = theMsgsTable.NewRow();     //新行;
                //theRow[id] = ""; 行ID可以自加得到!!!!
                theRow["msgText"] = inp_TheMsgText;                   
                theRow["GetUserID"] = inp_GetUser_ID;
                theRow["SendUserID"] = inp_SendUser_ID;
                theRow["SendUserName"] = inp_SendUser_Name;
                theRow["SendTime"] = System.DateTime.Now;
                theMsgsTable.Rows.Add(theRow);    // 将该行数据添加进表
                theMsgsTable.AcceptChanges();
                return true;
            }        /// <summary>
            /// 得到发给某人的短消息
            /// </summary>
            /// <param name="inp_GetUser_ID">某人的ID</param>
            /// <returns>DataTable</returns>
            public DataTable GetSomeBodyMsgs(string inp_GetUser_ID)
            {
                DataTable theBackTable = null;
                if (inp_GetUser_ID != null && inp_GetUser_ID != "" && DAL.DBBase.IsInt(inp_GetUser_ID))
                {
                    DataView theDV = new DataView(theMsgsTable);
                    theDV.AllowDelete = true;
                    theDV.AllowEdit = true;
                    theDV.AllowNew = true;
                    theDV.RowFilter = "GetUserID = " + inp_GetUser_ID;
                    theDV.Sort = "SendTime";
                    theBackTable = theDV.ToTable();//从视图中取值
                    for (int i = 0; i < theDV.Count; i++)
                    {
                        theDV.Delete(i);
                    }
                    theMsgsTable.AcceptChanges();
                }
                return theBackTable;
            }
        }
      

  3.   

    很久以前的代码,关于主键设的有问题,时间长了就溢出了,我也没改你还是改成用guid做主键吧。
      

  4.   

    NIIT? 好熟悉的啊,可以参考 http://zixun.mylegist.com 的实现。
      

  5.   


    --NIIT,莫非阁下也是NIIT出身?呵呵,你给的只是一个留言系统,感觉不是即时聊天,先谢谢了。
      

  6.   

    事实上由于我的应用还有一些后继的入库操作才要那个id字段的,你要是只做ajax聊天把,这个id字段直接删除就行了。在global的application_star里实例化就可以用了Application["TheGlobalMsg"] = new TheGlobalMsgs();前台用ajax每秒一取,就行了,很简单的
      

  7.   


    --呜呜,可惜我菜鸟,Ajax还在看,要不这样,你告诉我需要用到哪些知识,我抹黑冲下电,下午开会可能就要我交时间表了,谢谢了!
      

  8.   

    晕不会吧,你自己看jquery去吧,我自己用了个超轻的小类//建立 Ajax 类 
    //其中参数
    // url 为指定发起请求的地址
    // parms 为要发送的参数串(GET方式时加入请求url中,POST方式时需要自行拼接)
    // method 为请求方式能且只能设定为GET POST
    // callback 为在Ajax类实例化时指定的回调函数,即回送数据处理方法
    // 可再加一个 false 指定用同步方法function Ajax (url, parms, method, callback)
    {
        this.url = url;
        this.parms = parms;
        this.method = method;
        this.callback = callback;
        if(Ajax.arguments[4] == false)
        {
            this.async = false;
        }
        else
        {
            this.async = true;
        }
        this.create();
        this.req.onreadystatechange = this.dispatch (this);
    }
    //Ajax类的方法 dispatch 需要一个 Ajax 类实例 做为参数
    Ajax.prototype.dispatch = function (ajax)
    {
        function funcRef()
        {
            if (ajax.req.readyState == 4)
            {
                if (ajax.callback)
                {
                    ajax.callback (ajax.req);
                }
            }
        }
        return funcRef;
    }//Ajax类的方法 request 使用Ajax类的设定 发送请求
    Ajax.prototype.request = function ()
    {
        if (this.method == "POST")
        {
            this.req.open("POST", this.url, this.async);
            this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            this.req.send (this.parms);
        }
        else if (this.method == "GET")
        {
            this.req.open("GET", this.url + this.parms, this.async);
            this.req.send (null);
        }
    }//Ajax类的方法 setAsync 使用Ajax类的设定 同异步方式
    Ajax.prototype.setAsync = function (async)
    {
        this.async = async;
    }//Ajax类的方法 create 创建一个Ajax中使用的 XMLHTTP 对象
    Ajax.prototype.create = function ()
    {
        var xmlhttp;
        
        
        //下一条语句用来激活条件javascript编译
        /*@cc_on
        @if (@_jscript_version >= 5)
        try
        {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
                xmlhttp = false;
            }
        }
        @else
        xmlhttp = false;
        @end @*/
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
            try
            {
                xmlhttp = new XMLHttpRequest();
            }
            catch (e)
            {
                xmlhttp = false;
            }
        }
        this.req = xmlhttp;
    }//得到XML中的某个成员 doc_el 为文档对象, name 为指定的标签名 , idx 为序号(在文档中的第多少个)
    function get_element (doc_el, name, idx)
    {
        var element = doc_el.getElementsByTagName (name);
        if(element)
        {
            if(element[idx])
            {
                return element[idx].firstChild.data;
            }
            else
            {
                return "";
            }
        }
        else
        {
            return "";
        }
    }
    /*使用示例
        var ajax = new Ajax("sys_appdb_mt_form_webservice.asmx/AppendInput",strpost,"POST",function (req)
            {
                //回调函数(仅可获取非常严格定义的XML文件,例如根结点中必须有 xmlns 必须定义输出流的 字符集,建议在服务器端使用webservice而不是一般应用程序的方式返回值,另返回值必须有根结点,所以不可直接返回字符串。)
                var doc_el = req.responseXML.documentElement;
                
                // Extract values from XML structure returned by
                // by Ajax (XMLHttpRequest) call.
                
                //开始获取数据
                //alert(req.responsetext);
                var returnFlag = get_element (doc_el, "ReturnFlag", 0);
                var errMsg = get_element (doc_el, "ErrMsg", 0);
                            
                //开始使用数据
                //进行数据处理
            }
        );    //同步
        var ajax = new Ajax("sys_appdb_mt_form_webservice.asmx/AppendInput",strpost,"POST",function (req)
            {
                //回调函数(仅可获取非常严格定义的XML文件,例如根结点中必须有 xmlns 必须定义输出流的 字符集,建议在服务器端使用webservice而不是一般应用程序的方式返回值,另返回值必须有根结点,所以不可直接返回字符串。)
                var doc_el = req.responseXML.documentElement;
                
                // Extract values from XML structure returned by
                // by Ajax (XMLHttpRequest) call.
                
                //开始获取数据
                //alert(req.responsetext);
                var returnFlag = get_element (doc_el, "ReturnFlag", 0);
                var errMsg = get_element (doc_el, "ErrMsg", 0);
                            
                //开始使用数据
                //进行数据处理
            },flase
        );
        ajax.request ();
    */
      

  9.   

    你还可以把我那个类改成json的说实话webservice返回的datatable挺烦的。我的老掉牙webservice
        public class user_msg_WebService : System.Web.Services.WebService
        {
            /// <summary>
            /// GetSomeBodyMsgs 得到某用户消息
            /// </summary>
            /// <returns></returns>
            [WebMethod(EnableSession = true)]
            public DataTable GetSomeBodyMsgs()
            {
                BLL.TheUser theLoginUser = (BLL.TheUser)Context.Session["the_User"];
                return ((TheGlobalMsgs)Application["TheGlobalMsg"]).GetSomeBodyMsgs(theLoginUser.USER_ID);
            }        /// <summary>
            /// AddMsgs 添加一个消息
            /// </summary>
            /// <param name="inp_GetUser_ID"></param>
            /// <param name="inp_TheMsgText"></param>
            /// <returns></returns>
            [WebMethod(EnableSession = true)]
            public bool AddMsgs(string inp_GetUser_ID,string inp_TheMsgText)
            {
                BLL.TheUser theLoginUser = (BLL.TheUser)Context.Session["the_User"];
                return ((TheGlobalMsgs)Application["TheGlobalMsg"]).AddMsg(theLoginUser.USER_ID, theLoginUser.TRUE_NAME, inp_GetUser_ID, inp_TheMsgText);
            }    }
      

  10.   


    --咦,我就想用webservice,呵呵!谢谢啦!
      

  11.   


    --嗯嗯,确实是有点赶,但是Boss是个工作狂!
      

  12.   

    感谢大家的回答,已经找到源码了,呵呵,PowerTalk,网上有下载的!提供给有需要的朋友!今天结贴,谢谢hwbox的耐心,sp1234的教诲!