asp.net – 通过调用.ashx页面下载文件
发布时间:2020-12-15 22:17:40 所属栏目:asp.Net 来源:网络整理
导读:我正在从主页客户端脚本( Jquery)请求.ashx页面,该脚本具有下载PDF文件的代码.当我调试它时,我可以看到执行“文件下载”代码,但文件没有下载. $.ajax({ type: "POST",url: "FileDownload.ashx",dataType: "html",success: function (data) { } } ); public c
我正在从主页客户端脚本(
Jquery)请求.ashx页面,该脚本具有下载PDF文件的代码.当我调试它时,我可以看到执行“文件下载”代码,但文件没有下载.
$.ajax({ type: "POST",url: "FileDownload.ashx",dataType: "html",success: function (data) { } } ); public class FileDownload : IHttpHandler { public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string fileName = "BUSProjectCard.pdf"; string filePath = context.Server.MapPath("~/Print/"); context.Response.Clear(); context.Response.ContentType = "application/pdf"; context.Response.AddHeader("Content-Disposition","attachment; filename=" + fileName); context.Response.TransmitFile(filePath + fileName); context.Response.End(); } 解决方法
您的文件正在下载,但是您可以在javascript上获取它,在您的调用的数据参数上,因为您使用Ajax调用它.
你使用一个处理程序 – 所以这里不需要ajax,使用javascript最简单的方法是: window.location = "FileDownload.ashx?parametres=22"; 或者用简单的链接作为 <a target="_blank" href="FileDownload.ashx?parametres=22" >download...</a> 啊,并通过网址发送参数,你不能这样发布. 您还可以阅读:What is the best way to download file from server (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 使用Groups进行分页的SignalR
- asp.net – 有没有办法隐藏架构或至少从Sql Server Managem
- asp.net – Server.Transfer对Google不可见吗?
- 扩展GridView实现的一个自定义无刷新分页,排序,支持多种数
- 发送文件时的ASP.NET文件名编码
- iis-6 – IIS 6上的ASP.NET路由
- .net – ServiceHost和WebServiceHost有什么区别?
- asp.net-mvc-5 – 依赖注入结构图ASP.NET Identity MVC 5
- asp.net-mvc – ASP.NET MVC表单处理未知数量的输入
- 将经典ASP应用程序迁移到ASP.NET
推荐文章
站长推荐
- asp.net-web-api – System.Web.Http.WebHost中的
- asp.net – 手动更新表单认证券:
- asp.net-mvc – Sitecore 7.5 MVC和HttpContext.
- asp.net-mvc – 如何将HTML表单转换为C#以进行Pa
- ASP.NET LinqDataSource数据绑定后,遇到[Missin
- ASP.Net会员登录问题
- https://github.com/hoyuhub
- asp.net-mvc – ASP.NET MVC中Rake路由的等价物
- asp.net-mvc – MVC 4在局部视图中使用分页列表
- asp.net-mvc-3 – mvc3 – 在不同的区域使用部分
热点阅读