Skip to content

Instantly share code, notes, and snippets.

Created June 7, 2017 06:06
What would you like to do?
function futch(url, opts={}, onProgress) {
return new Promise( (res, rej)=>{
var xhr = new XMLHttpRequest(); || 'get', url);
for (var k in opts.headers||{})
xhr.setRequestHeader(k, opts.headers[k]);
xhr.onload = e => res(;
xhr.onerror = rej;
if (xhr.upload && onProgress)
xhr.upload.onprogress = onProgress; // event.loaded / * 100 ; //event.lengthComputable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment