I feel like this is really easy, but I can not figure it out.
I want to set the currentUserId inside of the getCurrentUser function, which I would like to be able to call inside other functions.
Below is what I have now, and it returns undefined. What am I missing?
var currentUserId;
function getCurrentUser() {
$.ajax({
type: "GET",
url: '/set_user',
success: function(result) {
currentUserId = result.id;
return currentUserId;
},
error: function(err) {
console.log(err);
}
})
};
getCurrentUser();
console.log("current user id is " + currentUserId);