admin管理员组文章数量:1331597
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 = mon.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.");
}
});
}
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 = mon.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.");
}
});
}
Share
Improve this question
edited Aug 19, 2011 at 11:47
Daniel Hilgarth
174k40 gold badges344 silver badges449 bronze badges
asked Aug 19, 2011 at 11:42
Mayur BoradMayur Borad
1,2959 silver badges23 bronze badges
1 Answer
Reset to default 6You 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;
}
本文标签: jqueryHow To Open Download Dialog box in JavascriptStack Overflow
版权声明:本文标题:jquery - How To Open Download Dialog box in Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742267378a2443663.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论