I have this situation where I have to check something via AJAX and then return the result. Or simplified:
function isValid() {
$.ajax(URL, data, function(response) {
isValid = response;
});
return isValid;
}
but still can't make it.
I can access the reponse, but I can't make isValid return AFTER I get the reponse. For example the solution I meet everywhere:
function isValid() {
function checkOnServer(callback) {
$.ajax(URL, data, function(response) {
callback(response);
});
}
checkOnServer(function(response) {
alert(response);
});
}
I met this all over Stackoverflow, BUT the problem is:
- I don't want to alert this.
- I want to RETURN it from isValid().
===========================
EDIT: I forgot to mention that if you/me/we try to simply "return" from the "checkOnServer" - it will just return it to the success callback of the AJAX. But the goal here is to make "isValid" return the result ... :)