I make function in Aspx page and call this function from java script , Now i want to download files through Java script. But Download Dialog Doesn't Open.....
Download.Aspx:
string pid = Request.QueryString["Did"].ToString();
DataTable dt;
dt = common.GetFilePath(Convert.ToInt64(pid));
FilePath = dt.Rows[0]["FilePath"].ToString();
FileName = dt.Rows[0]["FileName"].ToString();
FilePath = System.Web.HttpContext.Current.Server.MapPath("~//" + FilePath + "");
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + FileName + "");
Response.WriteFile(FilePath);
Response.End();
Jquery:
function DownloadAttach(pid){
$.ajax({ type: "POST",
url: "http://localhost:1988/DownLoad.aspx?Did=" + pid,
开发者_运维知识库 dataType: "xml",
processData: true,
//error: function(XMLHttpRequest, textStatus, errorThrown) { ajaxError(XMLHttpRequest, textStatus, errorThrown); },
success: function(xml) {
//ShowMsg("projSaveMsg", "Attachment Deleted.");
}
});
}
You don't want to make an AJAX call for this - just redirect the browser:
function DownloadAttach(pid){
window.location = "http://localhost:1988/DownLoad.aspx?Did=" + pid;
}
精彩评论