diff --git a/demos/xhr/README.md b/demos/xhr/README.md index a8e3594..8056833 100644 --- a/demos/xhr/README.md +++ b/demos/xhr/README.md @@ -116,27 +116,20 @@ axios("/upload", {method: "POST", data: fd}); ## fetch -For downloading data, `response.blob()` resolves to a `Blob` object that can be -converted to `ArrayBuffer` using a `FileReader`: +For downloading data, `response.arrayBuffer()` resolves to an `ArrayBuffer` that +can be converted to `Uint8Array` and passed to `XLSX.read`: ```js fetch(url).then(function(res) { /* get the data as a Blob */ if(!res.ok) throw new Error("fetch failed"); - return res.blob(); -}).catch(function(err) { - /* error in getting data */ -}).then(function(blob) { - /* configure a FileReader to process the blob */ - var reader = new FileReader(); - reader.addEventListener("loadend", function() { - /* parse the data when it is received */ - var data = new Uint8Array(this.result); - var workbook = XLSX.read(data, {type:"array"}); + return res.arrayBuffer(); +}).then(function(ab) { + /* parse the data when it is received */ + var data = new Uint8Array(ab); + var workbook = XLSX.read(data, {type:"array"}); - /* DO SOMETHING WITH workbook HERE */ - }); - reader.readAsArrayBuffer(blob); + /* DO SOMETHING WITH workbook HERE */ }); ``` diff --git a/demos/xhr/fetch.html b/demos/xhr/fetch.html index b0a6d10..a85a7da 100644 --- a/demos/xhr/fetch.html +++ b/demos/xhr/fetch.html @@ -41,15 +41,11 @@ document.getElementById('outfile').innerHTML = '