Skip to content

Instantly share code, notes, and snippets.

@lorenmh
Last active January 9, 2016 21:32
Show Gist options
  • Save lorenmh/95efa027c3ef27944996 to your computer and use it in GitHub Desktop.
Save lorenmh/95efa027c3ef27944996 to your computer and use it in GitHub Desktop.
xhr.js
function xhr(params) {
var x = new XMLHttpRequest();
x.open(params.m, params.p, true);
x.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
x.send(params.d !== void 0 ? JSON.stringify(params.d) : void 0);
x.onload = function() {
params.fn(x.responseText);
}
};
@lorenmh
Copy link
Author

lorenmh commented Jun 30, 2015

params:
m = method,
p = path
fn = callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment