Created
March 27, 2016 01:25
-
-
Save rndme/eb319de510bc44251d67 to your computer and use it in GitHub Desktop.
simple promise-based ajax function for get and post
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
//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