$.hubConnection is not a function(…)

signalr, signalr-hub

Solution

I am not sure whether your version of jQuery is supported. I had strange side effects with the wrong version of jQuery being loaded or it being loaded multiple times. When working with JSPM `jspm resolve --only npm:jquery@2.2.4` helps.

These verisons work:

<script src="jquery-2.1.4.min.js"></script>
<script src="jquery.signalR-2.2.0.min.js"></script>

and

"jquery": "npm:jquery@2.2.4",
"ms-signalr-client": "npm:ms-signalr-client@2.2.5",

I also recommend to omit the "/signalr" postfix when specifying the `hubConnection`. It is added in automatically.

Problem

I ran into a problem with my SignalR project. I have created an console to run the SignalR and then trying to use it with my website (all running in localhost mode for now) SignalRSelfHost ``` using System; using Microsoft.AspNet.SignalR; using Microsoft.Owin.Hosting; using Owin; using Microsoft.Owin.Cors; using Microsoft.AspNet.SignalR.Hubs; namespace SignalRSelfHost { class Program { static void Main(string[] args) { // This will *ONLY* bind to localhost, if you want to bind to all addresses // use http://*:8080 to bind to all addresses. // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx // for more information. string url = "http://localhost:8080"; using (WebApp.Start(url)) { Console.WriteLine("Server running on {0}", url); Console.ReadLine(); } } } class Startup { public void Configuration(IAppBuilder app) { app.UseCors(CorsOptions.AllowAll); app.MapSignalR(); } } [HubName("myHub")] public class MyHub : Hub { public void Send(string name, string message) { Clients.All.addMessage(name, message); } } } ``` Index.Html ``` <script src="Scripts/jquery-3.1.1.min.js"></script> <script src="Scripts/jquery.signalR-2.2.1.min.js"></script> <script src="http://localhost:8080/signalr/hubs"></script> <script type="text/javascript"> $(function () { //Set the hubs URL for the connection //$.connection.hub.url = "http://localhost:8080/signalr"; //// Declare a proxy to reference the hub. //var chat = $.connection.myHub; var conn = $.hubConnection("http://localhost:8080/signalr"); var hubProxy = conn.createHubProxy('myHub'); conn.start().done(function () { }); }); </script> ``` Some of the above has been outcomented, because that is something i also tried but didnt work either. Can anyone tell me why i get the error: $.hubConnection is not a function(…)

Original source