使用Ajax的JSP下载文件

下载文件" title="下载文件">下载文件,我正在使用ajax。我有三种状态:

"Download file" - before you click on the link.

"File is downloading..." - while the file is downloading

"Download file" - if the file was generated successful

"Error while downloading file" - if there was any error while download the file.

我正在使用JSP,jQuery Ajax。如何确定使用ajax下载文件时出错或下载成功。

回答:

您不能使用ajax下载文件并使它有用。Ajax响应已加载到javascript内存中。Javascript没有磁盘访问权限来保存该文件。

因此最好使用标头“ content-type” Content-Disposition:attach;以常规方式进行操作 使用常规请求的filename

=“ file name.ext”。

这将下载文件,浏览器将为用户提供保存文件的选项。另请注意,这不会重新加载您的页面。

以上是 使用Ajax的JSP下载文件 的全部内容, 来源链接: utcz.com/qa/410487.html

回到顶部