Created
August 7, 2018 20:14
-
-
Save kllaudyo/b58e3ef89bf89dcf6865a730a8fa757c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const ajax = (url, {method="GET", body=null, headers={}, mode}, onProgress=()=>{}, onStartProgress=()=>{}, onStopProgress=()=>{}) => { | |
return new Promise((result, reject) => { | |
const ajax = new XMLHttpRequest(); | |
ajax.open(method, url, true); | |
for(let [key, value] of headers) | |
ajax.setRequestHeader(key, value); | |
if(mode==='cors') | |
ajax.withCredentials = false; | |
ajax.onload = () => result(ajax.responseText); | |
ajax.onerror = reject; | |
ajax.onloadstart = onStartProgress; | |
ajax.onloadend = onStopProgress; | |
ajax.onprogress = onProgress; | |
ajax.send(body); | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment