Tôi đang yêu cầu trang .ashx từ tập lệnh phía máy khách trang chính (Jquery) có mã để tải xuống tệp PDF. Khi tôi gỡ lỗi, tôi có thể thấy việc thực thi mã "tải xuống tệp" nhưng tệp không tải xuống.tải xuống tệp bằng cách gọi .ashx trang
$.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();
}
bài đăng này có thể hữu ích? http://stackoverflow.com/questions/1999607/download-and-open-pdf-file-using-ajax –