I am download a file by going through .aspx page and which returns a file
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
String Header = "Attachment; Filename=" + sFileName;
HttpContext.Current.Response.AppendHeader("Content-Disposition", Header);
FileInfo Dfile = new FileInfo(HttpContext.Current.Server.MapPath(sFilePath));
HttpContext.Current.Response.WriteFile(Dfile.FullName);
HttpContext.Current.Response.End();
and that's fine.
I want to be able to do this via async ajax call using jQuery so that while the file is being downloaded user sees a gif spinner animation.
$("#showbusy").fadeIn();
$.ajax({ async : true, type: "GET", url: "download.aspx",
contentType: "application/text; charset=utf-8",
success: function (data) {
$("#showbusy").hide();
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
$("#showbusy").hide();
}
});
If I go directly to the .aspx page the file downloads, but this is not working by doing an ajax call to this page for some reason. I can see data is being returned in Firebug but once it completes the download it just sits there in memory.
How do I actually trigger a save file dialog on the browser side after the file download data has been received?