Javascript SignalR callback not working

I have a hub class:

public class ChatHub : Hub
{
    // Send message
    public void Send(string message)
    {
        Clients.addMessage(DateTime.Now.ToString("HH:mm:ss") + " " + message);
    }
}

And javascript:

// Proxy created on the fly
var chat = $.connection.chatHub;

// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function(message) {
    alert("message:" + message);
    $('#chat').append('<div>' + message + '</div>');
};


$("#sendButton").click(function () {

    // Call the chat method on the server
    chat.send($('#message').val())
        .done(function () {
            console.log('Success!')
        })
        .fail(function (e) {
            console.warn(e);
        })
});

// Start the connection
$.connection.hub.start();

All connections are in order: enter image description here

If I use a breakpoint here Clients.addMessage (DateTime.Now.ToString ("HH: mm: ss") + "" + message); everything is fine.

But I am not getting a javascript function callback. alert ("message:" + message); never performs

+5
source share
1 answer

Have you added the Client Side Signalr Hub?

<script src="/signalr/hubs" type="text/javascript"></script>
+3
source

All Articles