这里我使用sql dependancy方法来更改db: 1.我希望在db
的每次更改中获得类似fb的通知计数器 public static void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
SqlDependency sqlDep = sender as SqlDependency;
sqlDep.OnChange -= dependency_OnChange;
// string message="added";
GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.All.notify("added");
// from here we will send notification message to client
}
}
这是我的jquery代码,我想获得通知计数器:
但代码不起作用,并且不会从sqldependancy方法处理字符串值。
$(function()
{
// Proxy created on the fly
var job = $.connection.myHub;
// Declare a function on the job hub so the server can invoke it
job.client.notify = function (message) {
//
if (message && message.toLowerCase() == "added") {
updateNotificationCount();
}
};
// Start the connection
$.connection.hub.start();
updateNotificationCount();
});
function updateNotificationCount() {
var count = 10;
count = parseInt($('#noti_Counter').html()) || 0;
count++;
$('#noti_Counter')
.css({ opacity: 0 })
.text(function () {
return "" + count + "";
})
// ADD DYNAMIC VALUE (YOU CAN EXTRACT DATA FROM DATABASE OR XML).
.css({ top: '-10px' })
//.append('' + count + '')
.animate({ top: '-2px', opacity: 1 }, 500);
}