I have the following javascript code:
function requestUserList(){
//El primer paso es obtener de PHP toda la información de los usuarios
var ret;
jQuery.ajax({
type: "POST",
url: 'userfunctions.php',
dataType: 'json',
data: {functionname: 'all_user_data'},
success: function (obj) {
// if (obj.error == ""){
// for (i = 0; i < obj.users.length; i++){
// addAUser(obj.users[i],i);
// }
// }
// else{
// postErrorMessage(obj.error);
// }
console.log("Number is " + obj.users.length);
ret = obj;
}
});
console.log("Going back. N is " + ret.users.length);
return ret;
}
The problem is that the message "Number is" is printed in the correct value in the console. However on the second console print ("Going back. N is") I get the error that users is not a property of undefined. I'm assigning the return value incorrectly, somehow, but I don't know why. Can anyone help me? I want obj to be the return of the function.