$(document).ready(function () {
$("#anca").click(function (e) {
viewModel.CurrentVisit.GetById(StartValidation);
//Below statement executes before startValidation callback function //is executed
var x= true;
});
});
As, you can see here I am calling the function GetById and StartValidation is the callback function
self.GetById = function (SuccessCallback) {
var UId= self.Id();
UId = UId.replace('emp/', '');
$.ajax({
type: "GET",
url: "/api/v1/emp/" + UId,
traditional: true,
success: function (data) {
SuccessCallback(UserId);
},
error: function (data) {
debugger;
}
});
}
The callbackfunction is defined as such
function StartValidation(UserId) {
if (viewModel.CurrentUser.Id() != UserId) {
alert('Fail');
return false;
}
}
Basically the callback function executes later and the statement var x= true; executes first. i understand its anasync call so how do I wait for callback function to complete beore the statement var x= true; is executed ?