Skip to content

Instantly share code, notes, and snippets.

@amosrivera
Created August 7, 2015 19:27
Show Gist options
  • Save amosrivera/43c7a1453dcfc55826c4 to your computer and use it in GitHub Desktop.
Save amosrivera/43c7a1453dcfc55826c4 to your computer and use it in GitHub Desktop.
function get(url, data, callback){
if(typeof data === "function") {
callback = data;
data = {};
}
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type","application/json");
xhr.send(JSON.stringify(data));
xhr.onreadystatechange = function() {
callback(xhr.responseText, xhr.statusCode);
}
}
get("exmaple.com", function(data){
console.log(data);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment