i have following code call method on hub client page
var app = $.connection.myhub; $.connection.hub.start().done(function () { $('#mylink').click(function (e) { e.preventdefault(); app.server.mymethod(); }); ).fail(function (error) { console.log('invocation of start failed. error: ' + error) });
this code works fine after time passed, when click link again, following error
signalr: connection must started before data can sent. call .start() before .send()
the link click event inside
start().done()
if connection not started how event handler link click triggered.if because of connection timeout how can handle exception , redirect user login page.
why code inside
.fail()
not execute
recommended reading: connection lifetime events in signalr
this theory whats happening. can confirm turning on client side logging - add $.connection.hub.logging = true;
before start()
call.
- and 3. connection started ok - this code works fine after time.... same reason,
.fail()
not executed.
but after connection established, there can short or longer disconnects. client trying reconnect time (disconnect timeout) , if not successful, it'll give , need call .start()
again (in disconnected
handler example).
by handling 'disconnected' event
$.connection.hub.disconnected(function() {});
Comments
Post a Comment