|
案例:
给客户在做一站内消息的功能,客户要求用户A给用户B发一信息,用户B如果在线,在1分钟之内就要收到信息提示。
实现:
1.下载AjaxPro.2.dll控件,将它引用到项目里。
2.修改配置文件web.config:
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
3.在页面中注册AJAX
protected void Page_Load(object sender, EventArgs e)
{
#region 注册无刷新
AjaxPro.Utility.RegisterTypeForAjax(typeof(main_menu));//main_menu为我当前页面的类名
#endregion
}
4.编写前台调用的获取当前用户的新信息的方法
/// <summary>
/// 查看用户当前的收件箱
/// </summary>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string getxx()
{
int news = 这里从数据库中取新信息的数目
return news.ToString();
}
5.前台页面中通过javascript设置定时函数来执行获取当前用户的收件箱新信息的数量
<script language="javascript" type="text/javascript">
<!--
setInterval("getque()",60000);//间隔时间为一分钟,即每隔1分钟从数据库中读取一次数据
///取当前用户的新信息
function getque()
{
var getobject = main_menu.getxx(callback);//返回新信息的数量
}
function callback(res) //回调函数
{
if(res.value>0)//如果新信息的数量大于0则给用户弹窗口提示,这里只是测试,您可以用其它方法来实现提示
{
if(confirm("您收到"+res.value+"条新信息,点击确定查看"))
{
parent.frames["main"].l-o-c-a--t-i-on.href="admin_xx.aspx"; //点击确定后进入当前用户的收件箱页面。
}
}
}
-->
</script>
效果图:
'800')this.width='800';if(this.height>'600')this.height='600';" border=0>
|