The title might be a bit strange, but I'll try to explain.
I do an API call to validate some data. For this I use the following function:
function validateAddress(address) {
var validationURL = "/api/validateAddress/"+address;
$.getJSON(validationURL, function(data, textStatus, jqXHR){
if (textStatus === "success") {
return data.isValid
}
}));
}
// And then in other parts of the code I want to do something like:
if (validateAddress(address)) {
// do something awesome right here..
}
The problem with this is of course that it is an async call, which causes validateAddress() to not return anything, because it ends before the API call has returned any result.
So how can I actually make validateAddress() return the result of the api call? All tips are welcome!