Skip to content

Instantly share code, notes, and snippets.

@mrded
Created January 4, 2015 18:38
Show Gist options
  • Save mrded/6b1c0c9909cf0f497cc7 to your computer and use it in GitHub Desktop.
Save mrded/6b1c0c9909cf0f497cc7 to your computer and use it in GitHub Desktop.
JS: Function with callback.
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