I am looking for the quick and dirty answer. I am just blanking, and after staring at a screen for over 12 hours now, I think I am shot.
I want to do a simple SignalR application as a tutorial. I found this example, but I keep getting the error that tickets is undefined. I have found a couple more, and keep getting the same error. I compared the sample project to mine and I cannot find any descrepencies.
It seems as though $.connection.ticketHub
or $.connection.chat
are returning undefined objects. Is there something special that I need to do with /signalr/hubs
? Any other thoughts are greatly appreciated.
You need to add the /signalr/hubs to the page, it's a javascript dynamically generated by SignalR containing method stubs for your hubs and the methods on the hubs.
So if you have a .NET-hub named TestHub
, with a method called SendMessage(string message)
javascript will be generated so you can from JavaScript call: $.connection.testHub.sendMessage("some message to server");
Point your browser to the url: /signalr/hubs, and you should get a javascript.
about 150 lines down you will see the ticketHub stub:
$.extend(signalR, {
ticketHub: {
_: {
hubName: 'YourNameSpace.TicketHub',
ignoreMembers: ['someMethod', 'namespace', 'ignoreMembers', 'callbacks'],
connection: function () { return signalR.hub; }
},
You can use Mozilla Firebug plugin or Chrome developer tools (wrench-icon->Tools->Developer Tools) to see what's sent to and returned from server.
EDIT: There was a bug in SignalR preventing /signalr/hubs to be correctly generated (it didn't generate the method stubs). https://github.com/SignalR/SignalR/issues/134
EDIT2: you could have a incorrect script tag, try:
<script src="@Url.Content("~/signalr/hubs")" type="text/javascript"></script>
or you haven't referenced the SignalR.AspNet.dll
assembly. If I recall correctly it's that assembly that wires up the route to /signalr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With