2

I am trying to add SignalR into my MVC application. Every required script to initialize SignalR loading well and in correct order like

Loading

but still when i am trying to read the $.connection.hub.start() i am getting this below error

Hub Error

I am not getting what is going wrong here.

$(function () {
        $.connection.hub.start();
    });
    $.connection.hub.error(function (err) {
        console.log("HUB ERROR : " + err);
    });
    notebook.value('projectactivity', $.connection.projectactivity);

One more thing when i did console.log($.connection) into jquery.signalr*.js file i am getting the $.connection object into console.

Ashwini Verma
  • 7,477
  • 6
  • 36
  • 56
Ravi Mittal
  • 1,947
  • 4
  • 22
  • 37
  • may be this helps:http://stackoverflow.com/questions/11179644/signalr-connection-is-undefined – Ehsan Sajjad Apr 22 '14 at 06:06
  • http://stackoverflow.com/questions/20324806/signalr-uncaught-typeerror-cannot-read-property-chat-of-undefined – Ehsan Sajjad Apr 22 '14 at 06:07
  • i have already looked into these samples. – Ravi Mittal Apr 22 '14 at 06:15
  • if $.connection is defined when jquery.signalr* is executed, but not in $.ready, then either something is explicitly setting $.connection = undefined, or you have jQuery included twice, as I explained in this answer: http://stackoverflow.com/a/20352832/2001735 – Lars Höppner Apr 22 '14 at 22:36
  • 1
    i just tried to add the code right after /signalr/hubs script and without inside $(function(){}) and it works – Ravi Mittal Apr 23 '14 at 05:00

2 Answers2

0

you may need to init the start function a callback after signalR loaded, especially when the script is loaded dynamically rather than embedded in the document.

konghou
  • 557
  • 7
  • 20
0

I think you are missing to reference hub class.

    $(function () {
        var chat = $.connection.YourHubClass;

       $.connection.hub.start().done(function () {
         // initialization logic that has to occur after SignalR startup
       });

        $.connection.hub.error(function (err) {
           console.log("HUB ERROR : " + err);
        });
    });
Ashwini Verma
  • 7,477
  • 6
  • 36
  • 56
  • NO! I have tried your code sample with my Hub Class and getting the same error `Uncaught TypeError: Cannot read property 'projectActivity' of undefined` – Ravi Mittal Apr 22 '14 at 06:58
  • have you observed error message has been changed "Cannot read property 'projectActivity' of undefined". what is "projectActivity"? – Ashwini Verma Apr 22 '14 at 07:03
  • that is the name of my `Hub Class` – Ravi Mittal Apr 22 '14 at 07:07
  • try putting hub class in lower case. Example var chat = $.connection.projectactivity; – Ashwini Verma Apr 22 '14 at 07:12
  • 1
    NO! we can't because i have checked the proxy name in `~/signalr/hubs` and the name was `projectActivity`. One more thing i just tried to add the code right after `/signalr/hubs` script and without inside `$(function(){})` and it works – Ravi Mittal Apr 22 '14 at 07:21
  • Please see this thread "http://stackoverflow.com/questions/14146913/signalr-cannot-read-property-client-of-undefined". This error is related to class name. – Ashwini Verma Apr 22 '14 at 07:31