Javascript callback - how to return the result?

后端 未结 3 858
别跟我提以往
别跟我提以往 2020-12-10 17:55

I am struggling to totally understand callbacks and i am stumbling at the final hurdle.

Within JS I am calling a function which then calls a PHP function using a doj

3条回答
  •  隐瞒了意图╮
    2020-12-10 18:36

    A much cleaner answer:

    getPhp(number);
    
    function one(data){
        var test = data;
        // do what you want
    }
    
    function getPhp(number)
    {
    
        this.serviceBroker = new dojo.rpc.JsonService(baseUrl + '/index/json-rpc/');
    
        var result = serviceBroker.phpFunc(number);
    
        result.addCallback(
            function (response)
            {
                if (response.result == 'success')
                {
                    one(response.description);
                }
            }
        );
    }
    

提交回复
热议问题