mirror of https://github.com/artf/grapesjs.git
4 changed files with 33 additions and 3 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,25 @@ |
|||
import Promise from 'promise-polyfill'; |
|||
|
|||
window.Promise = window.Promise || Promise; |
|||
|
|||
export default typeof fetch == 'function' ? fetch.bind() : (url, options) => { |
|||
return new Promise((res, rej) => { |
|||
const req = new XMLHttpRequest(); |
|||
req.open(options.method || 'get', url); |
|||
req.withCredentials = options.credentials == 'include'; |
|||
|
|||
for (let k in options.headers || {}) { |
|||
req.setRequestHeader(k, options.headers[k]); |
|||
} |
|||
|
|||
req.onload = e => res(e.target.responseText, req); |
|||
req.onerror = rej; |
|||
|
|||
// Actually, fetch doesn't support onProgress feature
|
|||
if (req.upload && options.onProgress) { |
|||
req.upload.onprogress = options.onProgress; |
|||
} |
|||
|
|||
req.send(options.body); |
|||
}); |
|||
} |
|||
Loading…
Reference in new issue