ajax request to download an excel file is showing me truncated response

前端 未结 2 804
野的像风
野的像风 2021-01-20 11:01

I am trying to download an Excel file using Ajax (XMLHttpRequest).

On completion the responseText is found to have just 5 characters.
The network sniffing tool

相关标签:
2条回答
  • 2021-01-20 11:38

    The issue is probably that XMLHttpRequest doesn't ususally take binary data like an Excel file. If you just want to let the user download the file, read Ramiz's post. If you need to read the data in JavaScript, try switching to a text format like CSV (or better for parsing, JSON). If you really need to read a binary file, there are discussions of that here and here.

    0 讨论(0)
  • 2021-01-20 11:46

    Do not use Ajax call (xmlhttprequest) to download/upload files. Better do it on server side.

    0 讨论(0)
提交回复
热议问题