UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

31 lines (30 loc) 724 B
function get(options) { var xhr = new XMLHttpRequest(); xhr.open("get", options.url); xhr.responseType = options.responseType || "text"; if (options.onprogress) { xhr.onprogress = function(e) { if (e.lengthComputable) { var percent = e.loaded / e.total; options.onprogress(percent, e.loaded, e.total); } else { options.onprogress(null); } }; } xhr.onload = function(e) { if (xhr.status >= 400) { options.onerror && options.onerror(); } else { options.onload && options.onload(xhr.response); } }; if (options.onerror) { xhr.onerror = options.onerror; } xhr.send(null); } var request = { get }; export { request as default };