diff --git a/app.js b/app.js new file mode 100644 index 0000000..75e7b38 --- /dev/null +++ b/app.js @@ -0,0 +1,41 @@ +const apiUrl = "https://reqres.in/api/users"; + +function makeReq() { + const xhr = new XMLHttpRequest() + xhr.onreadystatechange = function () { + if (xhr.readyState === 4 && xhr.status === 200) { + const users = JSON.parse(xhr.response) + console.log(users.data.splice(0, 4)) + } + } + + xhr.open('GET', apiUrl) + xhr.send(); +} +makeReq() + + + +function getLog(url) { + const xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function () { + if (xhr.readyState === 4 && xhr.status === 200) { + console.log(JSON.parse(xhr.response)) + } + } + xhr.open('GET', url) + xhr.send() +} + +getLog(apiUrl) + +function get(url, cb) { + const xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function () { + if (xhr.readyState === 4 && xhr.status === 200) { + cb(xhr.response) // parse if you'd like + } + } + xhr.open('GET', url) + xhr.send() +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..d274f81 --- /dev/null +++ b/index.html @@ -0,0 +1,15 @@ + + + +
+ + + +