关于“如何从 jQuery 下载文件”的问题,我浏览了几十页,但仍然没有找到简单的解决方案。
我的 jQuery 里面有 ajax:
$.ajax({
url: "/Home/SaveQBMatter",
type: "POST",
data: JSON.stringify({ 'Matters': result, 'originalRecords': originalRecords, 'originalHours': originalHours, 'excludedHours': excludedHours, 'totalHours': totalHours }),
dataType: "json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.status == "Success") {
var DownloadableFile = data.message;
//HERE I NEED TO DOWNLOAD FILE
alert("Success! You will be redirect to the Home Page.");
var url = '@Url.Action("Index", "Home")';
window.location.href = url;
} else {
alert("Error occurs on the Database level!");
}
},
error: function () {
alert("An error has occured!!!");
}
});
在 data.message
中,我正在从 Action SaveQBMatter
完整文件路径中返回
我需要的只是让我的用户在重定向之前下载这个文件。有什么帮助吗?
注意:如果需要此信息,我正在使用 ASP.NET MVC
最佳答案
尝试使用这个插件来下载文件: http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/
关于c# - 从 jquery 下载具有现有路径的文件的最简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20336594/