Last active
December 14, 2015 16:08
-
-
Save jaeschrich/5112396 to your computer and use it in GitHub Desktop.
tiny ajax wrapper
This file contains 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
// 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