I can't seem to figure out how to retrieve the original
value from the json object. I keep getting lost...
{
"batchcomplete":"",
"query":{
"normalized":[{
"from":"dog","to":"Dog"
}]
,
"pages":{
"4269567":
{
"pageid":4269567,
"ns":0,"title":"Dog",
"original":
{
"source":"https://upload.wikimedia.org/wikipedia/commons/d/d9/Collage_of_Nine_Dogs.jpg",
"width":1665,
"height":1463
}
}
}
}
}
This is my current javascript code, but it's not working:
div.innerHTML += response.pages[0].original[3].source;
I am trying to retrieve the following URL:
https://upload.wikimedia.org/wikipedia/commons/d/d9/Collage_of_Nine_Dogs.jpg
I have been using this javascript function:
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
var div = document.getElementById('image');
div.innerHTML += response.pages[0].original.source;
})
.catch(function(error){console.log(error);});