Created
January 4, 2015 18:38
-
-
Save mrded/6b1c0c9909cf0f497cc7 to your computer and use it in GitHub Desktop.
JS: Function with callback.
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 httpGet(url, callback) { | |
var xmlHttp = new XMLHttpRequest(); | |
xmlHttp.onreadystatechange = function() { | |
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { | |
callback.call(this, JSON.parse(xmlHttp.responseText)); | |
} | |
}; | |
xmlHttp.open("GET", url, false); | |
xmlHttp.send(); | |
} | |
httpGet('/feedbacks/delete_me', function(response) { | |
console.log(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment