I have this method:
function getUserName(guid) {
var name = "Unbekannt";
$.getJSON(urlCurrent, {
"method" : "get_user_info",
"guid" : guid,
"auth_token" : temporaryAuthToken
}, function(data) {
if (data.status == 0) {
alert(data.result[0].name);
name = data.result[0].name;
}
});
return name;
}
Nearly all is working: the Ajax-Request gets data and fires the callback-function, so that
alert(data.result[0].name);
shows a popup with this value: “Forename Surname”
But then at
return name;
the method returns “Unbekannt”, although name should have the new value “Forename Surname”.
What happened and where´s the mistake?
Thx a lot
I would return the promise object from the function and act on it.
And, if you wanted to do the status check up front, .then is good for that.