Skip to content

Instantly share code, notes, and snippets.

@tobiasroeder
Created July 13, 2019 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasroeder/51c9f2af3b7d076a9edb505e6d4537f0 to your computer and use it in GitHub Desktop.
Save tobiasroeder/51c9f2af3b7d076a9edb505e6d4537f0 to your computer and use it in GitHub Desktop.
A function which load the content of a json file.
// 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