简体   繁体   English

用Java强制下载的方法

[英]Way to force download with Javascript

I need a way to 'force' the download of a file when the AJAX response of a Post is returned. 返回Post的AJAX响应时,我需要一种“强制”下载文件的方法。

I can't use window.open() because I don't have an useful URL. 我无法使用window.open()因为我没有有用的URL。

Is there any way using Javascript or Dojo toolkit to force the download of the file inside of the HTTP Response? 是否可以使用Javascript或Dojo工具包强制在HTTP响应中下载文件?

Your server needs to add the Content-Type and Content-Disposition headers to force a download. 您的服务器需要添加Content-Type和Content-Disposition标头以强制下载。

Content-Type: application/octet-stream
Content-Disposition: attachment; filename=filename.ext

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM