[jscript] Synchronous function execution
http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call
function checkSessionAuth(callback) {
$.ajax({
success: function (responseText, statusText, xhr, $xForm) {
if (responseText == "valid") {
if (typeof callback === 'function') {
/*invoke callback
-- go back to caller to execute rest of the script*/
callback.call(this);
}
}
}
});
}
function doSomething() {
checkSessionAuth(function () {
/* code here should execute after checkSessionAuth is executed.*/
});
}
$('#button').bind('click', function () {
checkSessionAuth(function () {
/* execute anything goes here
after checkSessionAuth callback is returned.*/
});
});