Receiving a .xls file using Ajax jquery POST

前端 未结 2 935
囚心锁ツ
囚心锁ツ 2021-02-06 19:57

I\'m attempting to return an Excel file through a Ajax POST to the server, the server generates the .xls file, however it doesn\'t pass through to the front end, i

2条回答
  •  一向
    一向 (楼主)
    2021-02-06 20:36

    You cannot use AJAX to download files from the server. The browser will deny Javascript from accessing the user's filesystem.

    You should look at providing a "download servlet" on your server side, which can set the appropriate headers to ensure the browser downloads the file or prompts the user to save a stream it is receiving from the Server.

    As noted here, you could also certain plugins that can provide you an AJAX-like experience. Internally they might be using iFrames to simulate AJAX-like behavior.

提交回复
热议问题