我正在从母版页客户端脚本(Jquery)请求.ashx页面,它具有下载PDF文件的代码。当我调试它时,我可以看到“文件下载”代码的执行情况,但文件没有下载。通过调用.ashx文件下载页面
$.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();
}
此主题可能对您有帮助吗? http://stackoverflow.com/questions/1999607/download-and-open-pdf-file-using-ajax –