I'm using Visual Studio 2012 Ultimate RC, SignalR 0.5.1 and Jquery 1.7.2 in an MVC4 application.
I have looked at: MVC4 SignalR "signalr/hubs" 501 Not Implemented Error
But it does not affect my issue (I am using IIS Express to debug).
When I try to utilize SignalR the $.connection variable is undefined. My server side code:
[HubName("tenantHub")]
public class TenantHub : Hub
{
...
void TenantChange(CrudAction action, Tenant tenant)
{
Clients.eventOccurred(action.ToString(), tenant);
}
}
Client side:
$(function() { var test = $.connection.tenantHub; });
Client side SignalR/hubs
is being referenced and I can see the JS code, it does not throw any errors. But referencing $.connection throws a Uncaught TypeError: Cannot read property 'tenantHub' of undefined
. Also tried to do the default chat example, it gives the same error. Is SignalR unsupported when utilized in VS2012 or am I just being stupid?
Ensure you don't have a duplicate hub name; [HubName("tenantHub")] - that is two or more hub classes decorated with the same name.
In reverse to John,
I had to add a / to the signalr/hubs declaration
ie.
Became
This us usually caused due to loading jQuery twice. Usually we are into the habit of loading the jQuery in the footer. Since the signalr complains and forces you to include jQuery library before the signalr-x.js.
You can include the jQuery before the signalr-x.js and you can do something like this in the footer where you include the jQuery plugin to avoid loading it twice:
Hope this helps. :)
Try taking
[HubName("tenantHub")]
off your class. Mine wouldn't work if I had those on there. Also try putting your hubs into a folder called"Hubs"
at the root of your project.I had the same problem in VS2012 RTM.
The problem was that I first added signalr in BundleConfig.cs and expected it to just work. But then using 'View Source' in the browser I noticed that signalr.js was included before jquery.js. signalr.js was included in the top of the page, jquery was included in the bottom of the page.
After some fiddling with BundleConfig signalr.js was included after jquery.js, and now signalr works like a charm!
I had a similar issue, mine was working form visual studio 2010 debug but not on localhost (IIS7.5 windows 7). I found that I had an extra slash in the definition for "signalr/hubs", I was using "/signalr/hubs". I also added JSON 2 js reference for browser compatibility. Note the order of declaring .js is important.
To find this issue I turned on logging as follows and looked in the console of the dev tools to see the error when deployed on localhost.
Hope this helps someone else. I'm playing with chrome, IE9, 10 on multiple PC's now - what a great library!