Last active
February 8, 2020 02:37
-
-
Save ksmarty/266d7b8cf3ef0970e447e3f6a1eb7444 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
// Text File | |
fetch('file.txt') | |
.then(response => response.text()) | |
.then(text => console.log(text)) | |
// ---------------------------------------------------------------------------- | |
// JSON File | |
fetch('file.json') | |
.then(response => response.json()) | |
.then(jsonResponse => console.log(jsonResponse)) | |
// ---------------------------------------------------------------------------- | |
// XML File | |
fetch('file.xml') | |
.then(response => response.text()) | |
.then(str => (new window.DOMParser()).parseFromString(str, "text/xml")) | |
.then(data => console.log(data)) | |
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
document.getElementById("json").innerHTML = JSON.stringify(json, undefined, 2); | |
// JSON.stringify(JSON data, replacer, spacing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment