Why am I getting a "TypeError: undefined is not a function" with a SignalR clientside callback?

StackOverflow https://stackoverflow.com/questions/23122213

  •  05-07-2023
  •  | 
  •  

문제

I'm running SignalR 1.0.1 and am trying to hook into some callbacks in my clientside javascript.

Consider the following code blocks:

var hub = $.connection.FooHub;

hub.disconnected(function () {                
            log("Server has disconnected");
        });

hub.received(function (data) {                
            log("Data Received");
        }); 

In both instances, I get the following error message: TypeError: undefined is not a function

Clearly, I'm missing something here. Can someone help point me out in the right direction?

Thanks, JohnB

도움이 되었습니까?

해결책

Try:

hub.disconnected = function () {                
        log("Server has disconnected");
    };

hub.received = function (data) {                
        log("Data Received");
    }; 

다른 팁

The hub proxy is created using camel-case (as is appropriate for JavaScript). So, if you define FooHub on your server, you access it on the client using $.connection.fooHub, not $.connection.FooHub.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top