Returning a response from a function every time end up as undefined function!!
var result = Checkusers();(result is undefined)
function CheckUser() {
var EmpName = $("#txtName").val();
$.ajax({
type: "POST",
url: location.pathname + "/UserExist",
data: "{Name:'" + EmpName + "'}",
contentType: "application/json; charset=utf-8",
datatype: "jsondata",
async: "true",
success: function (response) {
console.log(response.d);
var obj = eval('(' + response.d + ')');
return obj;
},
error: function (response) {
alert(response.status + ' ' + response.statusText);
}
});
}
i am calling this function as
var Result = CheckUser();
if(Result== false){
//do something
} else{
//do something
}
I have struggling with this from past one day!! I read in a section that it is because of 'Ajax is Asynchronous' . But how could i handle it??