Skip to content

Instantly share code, notes, and snippets.

@maecapozzi
Last active November 24, 2017 18:53
Show Gist options
  • Save maecapozzi/79fa4108af1223b12c51fca5af0548e2 to your computer and use it in GitHub Desktop.
Save maecapozzi/79fa4108af1223b12c51fca5af0548e2 to your computer and use it in GitHub Desktop.
const makeHTTPRequest = (url, methodType, callback) => {
const xhr = new XMLHttpRequest()
xhr.open(methodType, url, true)
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
callback(xhr.responseText)
}
}
xhr.send()
}
const getLogin = (response) => {
console.log(JSON.parse(response))
}
const url = 'https://api.github.com/users/maecapozzi'
makeHTTPRequest(url, 'GET', getLogin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment