ajax
request is asynchronous
. Don't use the sync: true
option, it's not really a good idea.
What you can do is to use the promise
that the ajax
returns, so:
function validateUserDetails(){
return $.ajax({
url: 'response.php?type=validateUserDetails',
type: 'POST',
async: false,
dataType: 'json',
data: {name: $("#checkout_name").val(), email: $("#checkout_email").val(), "country": $("#checkout_country").val(),
"city": $("#checkout_city").val()},
success: function(data){
console.log(data); // this is currently returning FALSE
}
});
}
$("#btn_go").on('click', function(){
validateUserDetails().done(function(data){
if(data == "someValue")
return "whatever you want";
});
});