locked
SignalR Async respose and Javascript Callback RRS feed

  • Question

  • User-1537395504 posted

    Hello,

    Please can you advise on best way to pass my response from a signalR hub to a function call which had a call back .. I've tried a global variable to stor the call back and call that on receive data but no luck. heres what i like to do;


    school.lib.setmytime = function(_time){

         console.log('mytime is :' + _time);
    }

    school.lib.gettime = data.getservertime(school.lib.setmytime);

    -----------------

    var myhub;

    data.connection = function(){
        $connection.hub.url = 'http://myserver.com:65442';
        $connection.hub.start();

        myhub = $.connection.adminHub;

        myhub.client.getServerTime = function (_time){
             //How do i access the callback
             //function in data.getservertime so as to return time to the school.lib.gettime?
        }

    }

    data.getservertime = function(callbak){

        myhub.server.getServerTime();

    }

    Tuesday, August 22, 2017 1:38 PM

All replies

  • User1771544211 posted

    Hi codetai,

    Could you please provide more information about the callback you want to use?

    And here is an answer that shows how to use callback with the SignalR client side function, please take it as reference.

    https://stackoverflow.com/a/15985708

    Best Regards,

    Jean

    Wednesday, August 23, 2017 7:09 AM