Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -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()
}
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ajax Fluency</title>
</head>

<body>
<script type="text/javascript" src="app.js"></script>
</body>

</html>