点击(此处)折叠或打开
-
该处是拿局部刷新消息数目来做示例:
-
-----------------------------------------前端页面代码-----------------------------------------------
-
-
<table>
-
<tr>
-
<td>
-
<img id="ImgMsg" alt="消?息?é" title="消?息?é" src="Images/Index/msg.ico" onclick="$('#ifrMain').attr('src','Msg/MsgNotRead.aspx');" />
-
</td>
-
<td>
-
<asp:Label ID="LabMsgNum" runat="server" Style="color: Red; font-size: small;">0</asp:Label>
-
</td>
-
<td>
-
;
-
</td>
-
<td>
-
<table>
-
<tr>
-
<td>
-
<img alt="登??陆?人¨?" title="登??陆?人¨?" src="Images/Index/User.ico" />
-
</td>
-
<td>
-
<asp:Label ID="LabUser" runat="server" Style="color: Green; font-size: small;"></asp:Label>
-
</td>
-
</tr>
-
</table>
-
</td>
-
<td>
-
;
-
</td>
-
<td>
-
<img alt="首???页°3" title="首???页°3" src="Images/Index/sy.gif" onclick="$('#ifrMain').attr('src','SystemSet/Main.aspx');" />
-
</td>
-
<td>
-
;
-
</td>
-
<td>
-
<asp:ImageButton ID="BtnExit" runat="server" ToolTip="退??出?" ImageUrl="Images/Index/tc.jpg"
-
OnClick="BtnExit_Click" />
-
</td>
-
</tr>
-
</table>
-
------------------------------------javascript代码-------------------------------------------------------
-
-
<script language="javascript" type="text/javascript">
-
//每?2000毫¨?秒?加¨?载?一°?次??,刷?é新?消?息?é数?y目?
-
window.setInterval("MsgNum()", 2000);
-
//刷?é新?消?息?é数?y目?
-
function MsgNum() {
-
$.ajax({
-
type: 'POST', //用??POST方¤?式??传??输??
-
dataType: 'json', / http://www.pprar.com
-
url: 'Msg/MsgHandler.ashx', //目?标?¨?地??址?¤
-
data: '',
-
//接¨?收??数?y据Y完?¨?毕??
-
success: function (json) {
-
//未??读¨?消?息?é数?y目?大?¨?于?¨?0,则¨°赋3值??,ê?并?é替??换?图??片?
-
if (json.notReadNum != '0') {
-
$("#LabMsgNum").html(json.notReadNum);
-
$("#ImgMsg").attr('src', 'Images/Login/User.jpg'); //动??态??的??flash
-
}
-
else {
-
$("#LabMsgNum").html(json.notReadNum);
-
$("#ImgMsg").attr('src', 'Images/Index/msg.ico'); //静2态??的??图??片?
-
}
-
}
-
});
-
}
-
</script>
-
------------------------------------------ashx代码------------------------------------------------------
-
using System;
-
using System.Web;
-
using System.Web.SessionState;
-
-
public class MsgHandler : IHttpHandler, IRequiresSessionState
-
{
-
string json = string.Empty; //返¤??回?给?js页°3面?的??结¨?果?,ê?用??于?¨?判D断?
-
int result = 0; //查¨?询??结¨?果?
-
public void ProcessRequest (HttpContext context) {
-
context.Response.ContentType = "text/plain";
-
//访¤?问¨?数?y据Y库a,ê?获?取¨?未??读¨?消?息?é数?y目?
-
MsgClass msg = new MsgClass();//消?息?é对?象¨?
-
json = "{\"notReadNum\":\"" + msg.GetMsgNotReadNum() + "\"}";
-
context.Response.Write(json);
-
}
-
-
public bool IsReusable {
-
get {
-
return false;
-
}
-
}
-
-
}