Skip to content

Instantly share code, notes, and snippets.

@tripplyons
Created September 8, 2017 03:02
Show Gist options
  • Save tripplyons/70d6be83d422cd219297a3d18012133a to your computer and use it in GitHub Desktop.
Save tripplyons/70d6be83d422cd219297a3d18012133a to your computer and use it in GitHub Desktop.
HTTP GET JavaScript
function get(url, cb) {
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
cb(xhr.responseText)
}
}
xhr.open("GET", url, true) // true for asynchronous
xhr.send(null)
}
function get(e,t){var n=new XMLHttpRequest;n.onreadystatechange=function(){4==n.readyState&&200==n.status&&t(n.responseText)},n.open("GET",e,!0),n.send(null)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment