Skip to content

Instantly share code, notes, and snippets.

@jaeschrich
Last active December 14, 2015 16:08
Show Gist options
  • Save jaeschrich/5112396 to your computer and use it in GitHub Desktop.
Save jaeschrich/5112396 to your computer and use it in GitHub Desktop.
tiny ajax wrapper
// not for POST/PUT requests
/**
* @function request
* @param {String} p The string to request (format "METHOD /path")
* @param {String} cb The callback. Takes 2 arguments, responseText and and XMLHttpReques object
*/
function request(p, cb){
var _p = p.split(' ' ),
method = _p[0],
path = _p[1],
req = new XMLHttpRequest();
req.open(method, path, true);
req.onreadystatechange = function changed(){
if (req.readyState !== 4){
return;
}
cb(req.responseText, req);
}
req.send()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment