locked
$.connection.(hubname) undefined RRS feed

  • Question

  • User1147605142 posted

    hello
    I tested SingnalR successfully. So I decided to integrate it into my web application. Integration is simple but Murphy's law it does not work.

    In practice I can not retrieve the hub
    "var chat = $ chat. connection.chatHub," the variable i is always "undefined

    Jquery libraries and singnalR load successfully.
    the path "~ / signalr / hubs" as well.
    The syntax of the code to call the object HUB as well.

    Now I can not understand the reason for failure.

    My doubt is that it is something on the web.config.
    The problem gives it to me with the debuger of vs2012 and I have not tried with IIS7

    Again, the example of the "Getting started with signalR" works perfectly.

    Thanks for any help.

    <!--Script references. -->
        <!--Reference the jQuery library. -->
        <script src='<%= this.ResolveClientUrl("Scripts/jquery-1.6.4.min.js")  %>'></script>
        <!--Reference the SignalR library. -->
        <script src='<%= this.ResolveClientUrl("Scripts/jquery.signalR-1.0.1.js")  %>'></script>
        <!--Reference the autogenerated SignalR hub script. -->
        <script src='<%= this.ResolveClientUrl("~/signalr/hubs")  %>'></script>
        
        <!--Add script to update the page and send messages.--> 
        <script type="text/javascript">
            $(function () {
                // Declare a proxy to reference the hub. 
                var chat = $.connection.chatHub;  //<--- var chat undfined ?????
    
                // Create a function that the hub can call to broadcast messages.
                chat.client.broadcastMessage = function (name, message) {
                    alert(name + ' ' + message);
                };
    
                // Start the connection.
                $.connection.hub.start().done(function () {
                    chat.server.send('name', 'start hub');
                    alert('start hub');
                });
    
                alert(chat);
            });
        </script>
    
    
    using System;
    using System.Web;
    using Microsoft.AspNet.SignalR;
    
    
    public class ChatHub : Hub
    {
        public void Send(string name, string message)
        {
            // Call the broadcastMessage method to update clients.
            Clients.All.broadcastMessage(name, message);
        }
    }
    
    
     public class Global : System.Web.HttpApplication
        {
    
            protected void Application_Start(object sender, EventArgs e)
            {
                // Register the default hubs route: ~/signalr/hubs
                RouteTable.Routes.MapHubs();
    
            }
    
    ....
    }

    Friday, March 8, 2013 6:05 AM

All replies

  • User1147605142 posted

    Having defined the App_Code folder, the class had the HUB must enter in there.

    SOLVED!!

    Friday, March 8, 2013 6:40 AM
  • User1336021323 posted

    I was also facing the same problem, The problem was that i was using the dlls of old SignalR version, Then i updated my SignalR files from NuGet and the problem was solved.

    Earlier i was using version 1.0.0 with old dll files, Now i am using new version of SignalR1.1.2.

    For complete example and  more reference please check http://aspnetworks.blogspot.in/2013/06/aspnet-signalr-connectionchathub-is.html.

    Thanks

    Ritesh

    Saturday, June 8, 2013 12:12 AM
  • User1328933117 posted

    I am experiencing undefined error in jquery connection line:

    Unhandled exception at line 37, column 13 in http://localhost:64301/
    0x800a138f - Microsoft JScript runtime error:
    Unable to get value of the property 'signalrchatroom': object is null or undefined

     

    I have followed the 3 steps from the link but may not have done it correctly as I had to adjust for MVC4

     

    <head>
            <meta charset="utf-8" />
            <title>@ViewBag.Title - My ASP.NET MVC Application</title>
            <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
            <meta name="viewport" content="width=device-width" />
            @Styles.Render("~/Content/css")
            @Styles.Render("~/Content/ChatStyle.css")
            @Styles.Render("~/Content/themes/base/jquery.ui.all.css")
            @Scripts.Render("~/bundles/modernizr")
    
            <script src="/Scripts/jquery-1.8.2.min.js"></script>
    
            <script src="/Scripts/ui/jquery.ui.core.js"></script>
            <script src="/Scripts/ui/jquery.ui.widget.js"></script>
            <script src="/Scripts/ui/jquery.ui.mouse.js"></script>
            <script src="/Scripts/ui/jquery.ui.draggable.js"></script>
            <script src="/Scripts/ui/jquery.ui.resizable.js"></script>
    
            <!--Reference the SignalR library. -->
            <script src="/Scripts/jquery.signalR-1.1.2.js"></script>
        
            <!--Reference the autogenerated SignalR hub script. -->
            <script src="/signalr/hubs"></script>

     

    Area where error occurs is:

     

                // Declare a proxy to reference the hub. 
                var chatHub = $.connection.chatHub;
    

    Would you mind pinpointing to me what is causing this error?

    Many thanks.

    Sunday, June 9, 2013 7:43 PM
  • Saturday, June 15, 2013 11:31 AM