Asp.net mvc 4 .done()在信号器中重新连接时未被调用
在我的MVC4 ASP.NET网页上,javascript中包含以下代码,用于处理与服务器的连接并重新连接到服务器(如果由于某种原因与服务器失去连接) 问题是,Asp.net mvc 4 .done()在信号器中重新连接时未被调用,asp.net-mvc-4,signalr,Asp.net Mvc 4,Signalr,在我的MVC4 ASP.NET网页上,javascript中包含以下代码,用于处理与服务器的连接并重新连接到服务器(如果由于某种原因与服务器失去连接) 问题是,$。连接.hub.start().done()没有被调用来响应重新连接的$.connection.hub.start()(只有在第一次发出时才会被调用)。我想知道这是一只虫子吗?如果没有,是否有一种等效的方法来提醒客户端start()已完成 // Start the signalR connection and request the d
$。连接.hub.start().done()
没有被调用来响应重新连接的$.connection.hub.start()
(只有在第一次发出时才会被调用)。我想知道这是一只虫子吗?如果没有,是否有一种等效的方法来提醒客户端start()
已完成
// Start the signalR connection and request the default page
$.connection.hub.start().done(function () {
console.info("$.connection.hub.start().done");
hubProxy.server.sendDefaultPage();
});
//if server goes away - reconnect to it
$.connection.hub.disconnected(function () {
console.info("disconnected");
setTimeout(function () {
$.connection.hub.start();
}, 5000); // Restart connection after 5 seconds.
});
您可以将连接启动逻辑放入函数中:
function startConnection() {
// Start the signalR connection and request the default page
$.connection.hub.start().done(function () {
console.info("$.connection.hub.start().done");
hubProxy.server.sendDefaultPage();
});
}
//if server goes away - reconnect to it
$.connection.hub.disconnected(function () {
console.info("disconnected");
setTimeout(startConnection, 5000); // Restart connection after 5 seconds.
});
然后,将在初始连接和重新连接时调用.done()回调