Skip to content

Instantly share code, notes, and snippets.

@rndme
Created March 27, 2016 01:25
Show Gist options
  • Save rndme/eb319de510bc44251d67 to your computer and use it in GitHub Desktop.
Save rndme/eb319de510bc44251d67 to your computer and use it in GitHub Desktop.
simple promise-based ajax function for get and post
//a promise-based ajax io
function pGet(url, data) {
return new Promise(function(y, n) {
var e = new XMLHttpRequest();
e.responseType="document";
e.onload=x=>y(e.response);
if(n) e.onerror=x=>n(e);
e.open(data?"POST":"GET", url, true);
setTimeout(e.send.bind(e,data), 0);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment