Created
February 12, 2020 22:17
-
-
Save k-marin/528b4267571993ca4c9c892d3a9884b3 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<h2>The XMLHttpRequest Object</h2> | |
<div id="container"></div> | |
<p id="demo">Let AJAX change this text.</p> | |
</div> | |
<button type="button" onclick="loadList()">Change Content</button> | |
<script> | |
function loadList() { | |
var xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
//console.log(this.readyState + this.responseText + this.responseType + this.status); | |
var json = JSON.parse(this.responseText); | |
var fruit = json.fruit | |
var text = "<ol>"; | |
for (i = 0; i < fruit.length; i++) { | |
text += "<li>" + fruit[i].type + "</li>"; | |
} | |
text += "</ol>" | |
document.getElementById("container").innerHTML = text; | |
}; | |
xhttp.open("GET", "https://raw.githubusercontent.com/k-marinov/json-resource/master/fruits.json", true); | |
xhttp.send(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment