ho provato anche così:
codice:
function getMediaId(id, async = true) {
let out;
$.ajax({
url: baseUrl + 'media/' + id,
type: 'GET',
aysnc: async,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false
}).done(function (res) {
out = res.source_url;
console.log("1:" + out);
}).fail(function (err) {
out = 'images/white.jpg';
});
console.log("2:" + out);
return out;
}
quello che non capisco è che mi esce prima il console contrassegnato come 2, con valore undefined.
e poi quello con 1, col valore corretto.
in teoria, forzando l'async, questo non dovrebbe succedere!