Coldfusion 下载文件

Coldfusion download file

我想通过调用 coldfusion 函数的 ajax 获取请求下载文件,但问题是在开发工具的 "network" 选项卡中我可以 "see" 内容,但是它不下载它。

这是存储在 cfc 中的我的 coldfusion 函数:

<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>

这是我的结果: http://imgur.com/FmPhlKx

我认为你应该在 Ajax 中删除下载功能,并将其移动到不同的进程...也许在不同的 URL 上调用它,如下所示:

http://websiteurl.com/download.php?file=xxxxx&sec_string=xxxxxx 等等

我希望这是有道理的:)