How can I pass true or false outside of this Ajax function? I need to return false on something and I cannot do that within Ajax
var zip = $('#order-zip').val();
var zipvalidated;
$.ajax({
type: 'POST',
url: 'checkzip.php',
data: {post:zip},
dataType: 'json',
success: function(data) {
zipvalidated = true;
if (data.response !== "success"){
console.log(data);
console.log ("sorry, we are not delivering in your area right now");
zipvalidated = false;
}
}
});
console.log (zipvalidated);
if (zipvalidated == false) {
return false;
}else{
console.log ("pass!")
}