1

This is my Signal R Client. I get this error when i run my client.(0x800a139e - JavaScript runtime error: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. .)

The exception comes from line $.connection.hub.start

There is a ServerHub class in a folder HUBS in my Server application which runs fine.

Can anyone help me out.. Thanks

<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
<script src="http://localhost:39670/MySignalRServer/signalr/hubs"></script>
 var ChatHubProxy = $.hubConnection("http://localhost:39670/MySignalRServer/signalr/hubs");
        var chat = ChatHubProxy.createHubProxy('ServerHub');

    chat.on("addNewMessageToPage",function (name, message) {
        // Add the message to the page.
          $('#discussion').append('<li><strong>' + htmlEncode(name)
            + '</strong>: ' + htmlEncode(message) + '</li>');
        });
      $.connection.hub.start({jsonp:true}).done(function () {
            $('#sendmessage').click(function () {
                // Call the Send method on the hub.
                chat.server.send($('#displayname').val(),       $('#message').val());
                alert("hiii");
                // Clear text box and reset focus for next comment.
                $('#message').val('').focus();
            });
        });
2
  • 1. check the hub name.2. check whether JS files are loaded propely Commented Oct 17, 2015 at 18:30
  • The hub name is correct....jquery files are also loaded properly....but exception on start says unable to load hub files...!! @J Santosh Commented Oct 17, 2015 at 18:39

1 Answer 1

3

Try change your code to :

<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
<script src="http://localhost:39670/MySignalRServer/signalr/hubs"></script>

    var chat = $.connection.ServerHub;  //here

    chat.on("addNewMessageToPage", function(name, message) {
        // Add the message to the page.
        $('#discussion').append('<li><strong>' + htmlEncode(name)
            + '</strong>: ' + htmlEncode(message) + '</li>');
    });

    $.connection.hub.start().done(function() {    //here
        $('#sendmessage').click(function() {
            // Call the Send method on the hub.
            chat.server.send($('#displayname').val(), $('#message').val());
            alert("hiii");
            // Clear text box and reset focus for next comment.
            $('#message').val('').focus();
        });
    });

And make sure that this address is good - <script src="http://localhost:39670/MySignalRServer/signalr/hubs"></script>

I always use this - <script src="/signalr/hubs"></script>

And add HubName Attribute

[HubName("ServerHub")]
public class ServerHub : Hub
{
    public string Send(string name, string message)
    {
        Clients.All.broadcastMessage(name, message);

        return null;
    }
}

or change this code :

 var chat = $.connection.ServerHub;

to

 var chat = $.connection.serverHub;

Demo project : https://github.com/czerwonkabartosz/SignalRDemo

Sign up to request clarification or add additional context in comments.

10 Comments

I will try this.... My server and client are in two different projects so I have to use localhost only right? @ Bartosz Czerwonka
Yes, run two project at a time and use localhost: port from your server projects - <script src="http:://localhost:port/signalr/hubs"></ script>. Here you can set the start of many projects - stackoverflow.com/a/21518254/4599089
I tried that.... Its showing js runtime error:Unable to get property 'on' of undefined or null reference...... @ Bartosz Czerwonka
I added that attribute on my server side in ServerHub.cs... but still i get the same error..... my server hub is placed in a folder HUBS.... could that be a problem??? @ Bartosz Czerwonka
Make sure that you can enter the address from your browser - localhost:[your port]/signalr/hubs
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.