I have tried many times with jQuery ajax call but it return value before updating it. i have googled it and tried lots of solutions no one work for me, i always get undefined value because function return value before ajax call complete. any help would be appreciate,
here is my code
$(document).ready(function() {
console.log(secondvalidation());
});
function onemorevalid() {
console.log("working");
//this ajax call return 1
return jQuery.ajax({
url: 'handler/email.php',
method: 'POST',
});
}
function secondvalidation() {
onemorevalid1 = new onemorevalid();
onemorevalid1.done(function(data) {
console.log("data " + data);
return data;
});
}
output on console is
working
undefined
data 1