Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can a SignalR JavaScript client detect when a connection with the server is lost?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
638 views
Welcome To Ask or Share your Answers For Others

1 Answer

A hub has a method disconnect which will allow you to add a callback when disconnection takes place:

myHub.disconnect(function() {
  alert('Server has disconnected');
});

If you aren't using hubs then the code for the disconnect method will help you out:

$(connection).bind("onDisconnect", function (e, data) {
  callback.call(connection);
});

This shows the syntax for hooking onto the onDisconnect event of the underlying connection.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...