Hey guys, I’m trying to write a function that retrieves a picture’s url using jQuery but I can’t get getJSON to pass on the info to the next get request which I believe is due to its asynchronous nature (which I admit I dont fully understand yet). I was hoping someone would be so kind as to help me understand this
let getImg = (id, artist) => {
let imgMain =
'https://en.wikipedia.org/w/api.php?action=query&titles=' +
artist +
'&prop=images&format=json&origin=*';
$.getJSON(imgMain, function(data) {
let imgKey = JSON.stringify(data.continue.imcontinue)
.replace(id, '')
.replace(/\|/g, '')
.replace(/['"]/g, '');
let imgJson =
'https://commons.wikimedia.org/w/api.php?action=query&titles=File:' +
imgKey +
'&prop=imageinfo&&iiprop=url&origin=*';
//NOT WORKING BELOW THIS LINE
$.getJSON(imgJson, function(data) {
let imgUrl = JSON.stringify(data.query.pages.id.imageinfo);
});
});
};