Using jquery

let url = "test.xlsx", oReq = new XMLHttpRequest(); oReq.open("GET", url, true); oReq.responseType = "arraybuffer"; oReq.onload = (e) => { let arraybuffer = oReq.response, data = new Uint8Array(arraybuffer), arr = []; for (let i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]); let bstr = arr.join(""), workbook = XLSX.read(bstr, { type: "binary" }), first_sheet_name = workbook.SheetNames[0], worksheet = workbook.Sheets[first_sheet_name], obj = XLSX.utils.sheet_to_json(worksheet); }; oReq.send(); 

Did so

 function ajaxRequest() { $.get('test.xlsx', (response) => { let data = new Uint8Array(response), arr = []; for (let i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]); let bstr = arr.join(""), workbook = XLSX.read(bstr, { type: "binary" }), first_sheet_name = workbook.SheetNames[0], worksheet = workbook.Sheets[first_sheet_name], obj = XLSX.utils.sheet_to_json(worksheet); }); }; ajaxRequest(); 

But console.log(worksheet); sees an empty object.

  • four
    what exactly? you and so the Ajax is used - ThisMan
  • @ThisMan, I dare to suggest that the author wants to know how this query will look on jquery - InDevX
  • @ InDevX. yes to jq - spoon 100500
  • all that before the line data = new ... delete and wrap in $.get(url, function(response){ ..... }) . send at the end also delete - teran
  • @teran made an example, but data = new Uint8Array (response) is empty. - spoon 100500

0