Below is a javascript function that i haved tried to return a status, but it's unable to return true false.It'just show not defined in console.log but "available" and "not available" is perfectly printed out.
function checkingeUserInput(){
var status;
$.ajax({
type:'POST',
dataType:'json',
data: userCheck,
url: api_url,
success:function(resp){
var cond = resp.items;
if(cond.valid==true){
status = true;
console.log('available');
}
if(cond.valid==false){
console.log('not available');
status = false;
}
}
});
return status;
}
And below a piece of code from click function to get the status true false
var status = checkingeUserInput();
console.log(status); // I have got undefined here when click function is execute.