This question already has an answer here:
-
How do I return the response from an asynchronous call?
32 answers
-
Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
6 answers
My code:
function validateAddress(type){
var status = true
if(type == 0 || type == 2){
$.get( "/user/status/0", function( data ) {
if(!data.status){
status = false
}
else
status = true
});
}
else{
$.get( "/status/1", function( data ) {
if(!data.status){
status = false;
}
else{
status = true
}
});
}
console.log(status)
return status
}
How to make sure the internal status is returned from function? At the moment it returns true all the time, because somehow the status value isn't changed. The AJAX part itself is working fine.
|