Created
July 13, 2019 14:23
-
-
Save tobiasroeder/51c9f2af3b7d076a9edb505e6d4537f0 to your computer and use it in GitHub Desktop.
A function which load the content of a json file.
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
// load JSON | |
function loadJSON(url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', url, true); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState === 4) { | |
if (xhr.status === 200) { | |
callback(JSON.parse(xhr.responseText)); | |
} else { | |
// callback([{}]); | |
} | |
} | |
}; | |
xhr.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment