右下角弹出框实现

来源:互联网 发布:0基础学编程 知乎 编辑:程序博客网 时间:2024/05/21 19:24

一切基于项目。

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

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

通过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);

        }


<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击