Created
August 7, 2015 19:27
-
-
Save amosrivera/43c7a1453dcfc55826c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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