I want the following function to return true or false based on my logic, but the function returning undefined.
function getUserData() {
$.ajax({
type: 'POST',
contentType: 'application/json',
url: 'myservice',
dataType: "JSON",
success: function (data) {
if (data.d.UserID > 0) {
return true;
} else {
return false
}
return false;
},
error: function (error) {
return false;
}
});};
if (getUserData()) {
//do something
} else {
//redirect
}
please do not consider it a duplicate, it is different, I dont want to return the callback functions I want to return true or false based on those callback functions.