How can I get the value outside the success after Mini Program requests the API?

the code is shown below:

clipboard.png

:

clipboard.png

clipboard.png

clipboard.png

question:
1, the position t.data.memberInfo of print 1 can get the value;
2, the position t.data of print 2 exists memberInfo;
3, and the position t.data.memberInfo of print 3 is undefined. What is the reason? What should we do about it?


function caozuo(data){
    //
    console.log(data);
}

success: function(res){
    caozuo(res);
}

suggest that the landlord take a look at asynchronous processing


callback "Promise" async/await

Menu