javascript - Issues with callback function -
this question has answer here:
- how return response asynchronous call? 21 answers
i have simple question has been bouncing on head how handle this. i've been using api requires callback function capture values, , i'm having issues in returning output of function other functions i'm using on project.
for example:
function a() { var callback = function(e) { var id = e.data.responsedata.id; }; api.getid(callback); }
if try call variable id, give me undefined i'm assuming id value not being passed available globally.
on other side if run this:
function a() { var callback = function(e) { var id = e.data.responsedata.id; console.log(id); }; api.getid(callback); }
it return me on console correctly value of id.
any ideas on i'm missing here?
thanks once again.
rafa
you need return variable "id" in function:
function a() { var callback = function(e) { var id = e.data.responsedata.id; return id; }; api.getid(callback); }
Comments
Post a Comment