Asp.net mvc 4 如何在我的web应用程序中的MVC4中创建类似facebook的通知框?
每次重新加载此页面时,都会启动新连接,并且在更新数据库数据通知时。client.updateNotifications=function(){ 警报(“3”); getAllNotifications()} 被多次调用。否则就可以了Asp.net mvc 4 如何在我的web应用程序中的MVC4中创建类似facebook的通知框?,asp.net-mvc-4,signalr-hub,Asp.net Mvc 4,Signalr Hub,每次重新加载此页面时,都会启动新连接,并且在更新数据库数据通知时。client.updateNotifications=function(){ 警报(“3”); getAllNotifications()} 被多次调用。否则就可以了 <script src="/Scripts/jquery.signalR-2.2.0.js"></script> <!--Reference the autogenerated SignalR hub script. --> &l
<script src="/Scripts/jquery.signalR-2.2.0.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="/signalr/hubs"></script>
<script type="text/javascript">
var ConnectionStarted = false;
$(function () {
alert("1");
// Declare a proxy to reference the hub.
var notifications = $.connection.notificationHub;
//debugger;
// Create a function that the hub can call to broadcast messages.
notifications.client.updateNotifications = function () {
alert("3");
getAllNotifications()
};
$.connection.hub.start().done(function () {
ConnectionStarted = true;
alert("2");
alert("connection started")
getAllNotifications();
}).fail(function (e) {
alert(e);
});
});
function getAllNotifications() {
var tbl = $('#messagesTable');
$.ajax({
url: '/Home/GetNotifications',
contentType: 'application/html ; charset:utf-8',
type: 'GET',
dataType: 'html'
}).success(function (result) {
tbl.empty().append(result);
}).error(function () {
});
}
</script>
var ConnectionStarted=false;
$(函数(){
警报(“1”);
//声明代理以引用中心。
var通知=$.connection.notificationHub;
//调试器;
//创建一个中心可以调用以广播消息的函数。
notifications.client.updateNotifications=函数(){
警报(“3”);
getAllNotifications()
};
$.connection.hub.start().done(函数(){
ConnectionStarted=true;
警报(“2”);
警报(“连接已启动”)
getAllNotifications();
}).失败(功能(e){
警报(e);
});
});
函数getAllNotifications(){
var-tbl=$('#messagesTable');
$.ajax({
url:“/Home/GetNotifications”,
contentType:'应用程序/html;字符集:utf-8',
键入:“GET”,
数据类型:“html”
}).成功(功能(结果){
tbl.empty().append(结果);
}).错误(函数(){
});
}