Skip to content

Instantly share code, notes, and snippets.

@elrumordelaluz
Created May 28, 2014 11:38
Show Gist options
  • Save elrumordelaluz/92eeaa3fe98c2d8899b9 to your computer and use it in GitHub Desktop.
Save elrumordelaluz/92eeaa3fe98c2d8899b9 to your computer and use it in GitHub Desktop.
(js) httpRequest with callback
var $ = {
core:function(u){
return new $.httpRequest(u);
},
httpRequest:function(url, callback){
var r = new XMLHttpRequest();
r.open("GET", url, true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
callback(r.responseText);
};
r.send();
}
};
// Use:
$.httpRequest("http://examplesite.com/myurl", function(data) {
// callback
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment