右下角弹出框实现

一切基于项目。

客户项目中需要对用户进行实时提醒。

谷歌,度娘问了下。大致有了思路。

通过Ajax方式实现(Jquery+ashx)

通过Jquery的$.post连接ashx取得相应数据,拼接成string字符串返回,然后用JquerUI插件显示(本文简化了,用Alert代替)。

aspx代码如下:

//此代码应放置在框架页中

function TimeFunction() {
            GetMsg();
            window.setInterval("GetMsg()", 240000); //每隔240000ms执行一次查询
        }

function GetMsg() {

            var userId = $("#<%=hfUId.ClientID %>").val();

           //ajax方式获取数据
            $.post("GetMsgHandler.ashx", { Action: "getMsg", userid: userId }, function (data) {
                if (data != "") {
                   alert(data);

// 用JqueryUI控件的写法:

//$.messager.show('<font color=red>系统消息</font>', '<div style="word-wrap: break-word; ">' + data + '</div>', 20000);
                }

            });
        }

TimeFunction() ;

 

ashx 代码如下:

public void ProcessRequest(HttpContext context)
      {

          context.Response.ContentType = "text/plain";       
          string resMsg1 = "";
          GetMsg(context, out resMsg1);//此方法用于去数据库查询数据,然后返回结果                  
          context.Response.Write(resMsg1);

        }

posted @ 2013-02-28 23:48  cn_king  阅读(4134)  评论(0编辑  收藏  举报