I have the following code:
Main.User = (function(){
var currentUser = ''
var get_current_user = function get_current_user(){
Main.Mod.do_ajax('home/get_user_pnp_id','GET',function(data){
currentUser = data.username;
},null);
console.log(currentUser); //Doesn't work. It logs empty string.
return currentUser;
}
return {
get_current_user : get_current_user,
}
})();
The 3rd parameter from Main.Mod.do_ajax()
is a callback success function from my ajax call. However I cannot set currentUser
inside that callback function.
What seems to be the problem?