0
我试图返回一个我所做的api调用的结果,但我一直在获取undefined作为输出。这里的代码:从回调函数返回一个变量javascript函数
function getProjects() {
var message;
gapi.client.dolapoapi.getProject({
'appid': "test4"
}).execute(function(resp) {
if (!resp.code) {
//get the response and convert it to a string
message = JSON.stringify(resp);
//console.log(resp); i get the correct output here
}
//console.log(message); i get the correct output here
});
//console.log(message); it returns undefined.
return message;
}
我不知道什么可能是错的。但我想要做的就是回到它的位置分配后的消息变量是什么:
message = JSON.stringify(resp);
谢谢。能够实施它。 –
@DolapoToki upvote和接受,如果它的工作 – Iceman