我想通过调用 Coldfusion 函数的 ajax get 请求下载文件,但问题是在开发工具的“网络”选项卡中我可以“看到”内容,但它不下载它。
这是我的 Coldfusion 函数,它存储在 cfc 中:
<cffunction name="download" access="remote" output="true">
<cfset file_name = "Test.xlsx">
<cfheader name='Content-Disposition' value='attachment; filename=#file_name#' charset='utf-8'>
<cfcontent type="application/msexcel" file="#file_name#" deletefile="false">
</cffunction>
这是我的 ajax 调用:
<script>
$.ajax({
method: "GET",
url: "ses/dev.cfc",
data: {
method: 'download'
},
cache: false,
success: function(data) {
console.log("Downloaded");
},
error: 'Not downloaded'
});
</script>
这是我的结果: /image/Q8qNy.jpg
最佳答案
我认为您应该在 Ajax 中删除下载功能,并将其移动到不同的进程...也许可以在不同的 URL 上调用它,如下所示:
http://websiteurl.com/download.php?file=xxxxx&sec_string=xxxxxx
等
我希望这是有道理的:)
关于javascript - 冷融合下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42707062/