Skip to content

Instantly share code, notes, and snippets.

@ramunasnognys
Last active June 7, 2020 18:53
Show Gist options
  • Save ramunasnognys/d6bc6a711c1fb2a6a2c61ba2446249e8 to your computer and use it in GitHub Desktop.
Save ramunasnognys/d6bc6a711c1fb2a6a2c61ba2446249e8 to your computer and use it in GitHub Desktop.
Getting JSON Data from URL
var getJSON = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "json";
xhr.onload = function () {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
let data = getJSON(
"http://private-38e18c-uzduotis.apiary-mock.com/config/cash-in",
function (err, data) {
console.log(data.max.amount);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment