2017-02-27 112 views
1

我越來越想訂閱SignalR樞紐事件時,出現以下錯誤:樞紐事件

$ .connection.hub.connectionSlow不是一個函數

我的代碼:

var connection = $.hubConnection(); 
serviceRequestHubProxy = connection.createHubProxy('myHub'); 
connection.start() 
    .done(function() { alert('connected!'); }); 
$.connection.hub.connectionSlow(function() { 
    alert('connection slow!'); 
}); 

我正在使用SignalR 2.2。我究竟做錯了什麼?

回答

1

當您不使用生成的代理時,$ .connection將不可用。你應該改變。

var connection = $.hubConnection(); 
serviceRequestHubProxy = connection.createHubProxy('myHub'); 

connection.start() 
    .done(function() { alert('connected!'); }); 

connection.connectionSlow(function() { 
    console.log('We are currently experiencing difficulties with the connection.') 
}); 

閱讀more