Created
August 13, 2020 03:25
-
-
Save moisescastillo/ef7c4bdb02cacfb2be3962bd4129cdf3 to your computer and use it in GitHub Desktop.
Example JSON request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var requestJSON = 'https://mdn.github.io/learning-area/javascript/oojs/json/superheroes.json'; | |
let request = new XMLHttpRequest(); | |
request.open('GET', requestJSON); | |
request.responseType = 'json'; | |
request.send(); | |
request.onload = function() { | |
let data = request.response; | |
let members = data.members; | |
members.forEach(function(value, index) { | |
console.log(`Name: ${value.name}`); | |
console.log(`Age: ${value.age}`); | |
console.log(`Secret Identity: ${value.secretIdentity}`); | |
if (value.powers.length > 0) { | |
console.log(`Powers:`); | |
for (let i in value.powers) { | |
console.log(i, value.powers[i]); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment