Last active
June 7, 2020 18:53
-
-
Save ramunasnognys/d6bc6a711c1fb2a6a2c61ba2446249e8 to your computer and use it in GitHub Desktop.
Getting JSON Data from URL
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
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