SignalR JS Client Methods Not Invoked

后端 未结 2 1307
醉酒成梦
醉酒成梦 2020-12-20 20:51

I\'m having trouble getting SignalR server-side Hub code to invoke JS client methods. The reverse is working fine - so when my client sends a message to the server it is del

2条回答
  •  抹茶落季
    2020-12-20 21:27

    When you hover over the Clients object, do you see all the functions you defined in JS?

    Anyway,I'm not sure why your way doesn't work, but this is how I wrote my client side, and it works. Maybe you could try this way.

    $(function () {
    
        var hub = $.connection.RatesHub;
    
    
        $.connection.hub.start().done(function () {
            /*Logic goes here*/
        });
    
        $.extend(hub.client, {
            FuncName: function (msg) {
                /*Logic goes here*/
            }
        });
    
    }
    

    Any function you want to be recognized in your server, use $.extend.

    Hope that helps.

提交回复
热议问题