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
  •  | 
  •  

Question

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

Was it helpful?

Solution

Try:

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

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top