I have a function, authenticate() that uses $post() to retrieve a session key from my server. I believe $post is an asynchronous call. Whenever I perform any action in my script, I want to ensure that I have a sessionKey, and if I do not have a sessionKey I want to authenticate(). My problem is how do I run performTask() after I have called authenicate()?
function foo() {
if (sessionKey) {
performTask();
} else {
authenciate();
performTask();
}
}
function authenticate() {
$.post(url, function(data) {
sessionKey = data.sessionKey;
});
}
EDIT: I also do not want to put in authenticate()'s callback function performTask() as authenticate() will be called from several different functions.