Can not return "result" in xhr.then (‘dojo/request/xhr’)

I have some problems when I return “result” in xhr.then() and I use dojo 1.10.4 Pls help me!

The below code which connects to API with xhr (‘dojo/request/xhr’) in dojo:

remandFlow: function(postData, flowId) {
        return xhr(this.REMAND_URL + flowId, {
            method: 'POST',
            data: postData,
            handleAs: 'json',
            headers: {'X-CSRFToken': cookie("csrftoken")}
        }).then(
            lang.hitch(this, function(result){
                return result;
            }),
            lang.hitch(this, function(error){
                return error;
            })
        );
    },

The below code which gets result of above code:

editStepUser: function(stepComponent, routeComponent) {

        this.model.remandFlow(postData).then(
            function(result){
                console.log(result) //I can not get it, It's undefined
                result.targeted_step_id = postData.route_step_id;
            },
            function(result){
                result.targeted_step_id = postData.route_step_id;
            }
        );
    },

So, in the second code, I can’t get result, result is “undefined”. Please help me, I’m a newbie dojo.

Thanks!!


Source: ajax

Leave a Reply