Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17991
  • 博文数量: 12
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2014-01-02 14:42
文章分类
文章存档

2015年(5)

2014年(7)

我的朋友
最近访客

分类: C#/.net

2014-09-22 12:26:00

 

点击(此处)折叠或打开

  1. 该处是拿局部刷新消息数目来做示例:
  2. -----------------------------------------前端页面代码-----------------------------------------------
  3.                 <table>
  4.                     <tr>
  5.                         <td>
  6.                             <img id="ImgMsg" alt="消?息?é" title="消?息?é" src="Images/Index/msg.ico" onclick="$('#ifrMain').attr('src','Msg/MsgNotRead.aspx');" />
  7.                         </td>
  8.                         <td>
  9.                             <asp:Label ID="LabMsgNum" runat="server" Style="color: Red; font-size: small;">0</asp:Label>
  10.                         </td>
  11.                         <td>
  12.                              ;&nbsp;
  13.                         </td>
  14.                         <td>
  15.                             <table>
  16.                                 <tr>
  17.                                     <td>
  18.                                         <img alt="登??陆?人¨?" title="登??陆?人¨?" src="Images/Index/User.ico" />
  19.                                     </td>
  20.                                     <td>
  21.                                         <asp:Label ID="LabUser" runat="server" Style="color: Green; font-size: small;"></asp:Label>
  22.                                     </td>
  23.                                 </tr>
  24.                             </table>
  25.                         </td>
  26.                         <td>
  27.                              ;&nbsp;
  28.                         </td>
  29.                         <td>
  30.                             <img alt="首???页°3" title="首???页°3" src="Images/Index/sy.gif" onclick="$('#ifrMain').attr('src','SystemSet/Main.aspx');" />
  31.                         </td>
  32.                         <td>
  33.                              ;&nbsp;
  34.                         </td>
  35.                         <td>
  36.                             <asp:ImageButton ID="BtnExit" runat="server" ToolTip="退??出?" ImageUrl="Images/Index/tc.jpg"
  37.                                 OnClick="BtnExit_Click" />
  38.                         </td>
  39.                     </tr>
  40.                 </table>
  41. ------------------------------------javascript代码-------------------------------------------------------
  42. <script language="javascript" type="text/javascript">
  43.     //每?2000毫¨?秒?加¨?载?一°?次??,刷?é新??息?é数?y目?
  44.     window.setInterval("MsgNum()", 2000);
  45.     //刷?é新??息?é数?y目?
  46.     function MsgNum() {
  47.         $.ajax({
  48.             type: 'POST', //用??POST方¤?式??传??输??
  49.             dataType: 'json', / http://www.pprar.com
  50.             url: 'Msg/MsgHandler.ashx', //目?标?¨?地??址?¤
  51.             data: '',
  52.             //接¨?收??数?y据Y完?¨?毕??
  53.             success: function (json) {
  54.                 //未??读¨?消?息?é数?y目?大?¨?于?¨?0,则¨°赋3值??,ê?并?é替???图???
  55.                 if (json.notReadNum != '0') {
  56.                     $("#LabMsgNum").html(json.notReadNum);
  57.                     $("#ImgMsg").attr('src', 'Images/Login/User.jpg'); //动??态??的??flash
  58.                 }
  59.                 else {
  60.                     $("#LabMsgNum").html(json.notReadNum);
  61.                     $("#ImgMsg").attr('src', 'Images/Index/msg.ico'); //静2态??的??图???
  62.                 }
  63.             }
  64.         });
  65.     }
  66. </script>
  67. ------------------------------------------ashx代码------------------------------------------------------
  68. using System;
  69. using System.Web;
  70. using System.Web.SessionState;
  71. public class MsgHandler : IHttpHandler, IRequiresSessionState
  72. {
  73.     string json = string.Empty; //返¤??回??js页°3面?的??结¨?果?,ê?用??于?¨?判D断?
  74.     int result = 0; //查¨?询??结¨?果?
  75.     public void ProcessRequest (HttpContext context) {
  76.         context.Response.ContentType = "text/plain";
  77.         //访¤?问¨?数?y据Y库a,ê??取¨?未??读¨?消?息?é数?y目?
  78.         MsgClass msg = new MsgClass();//?息?é对?象¨?
  79.         json = "{\"notReadNum\":\"" + msg.GetMsgNotReadNum() + "\"}";
  80.         context.Response.Write(json);
  81.     }
  82.  
  83.     public bool IsReusable {
  84.         get {
  85.             return false;
  86.         }
  87.     }
  88. }
阅读(593) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~