javascript - Generating file with ajax and allow user to download it? -


i have similar problem this: allowing users download files - asp.net , in case generating xlsx file ajax, , on ajax-called aspx page using:

response.clear(); response.contenttype = "application/octet-stream"; string filename = user.identity.name + "_report.xlsx"; response.addheader("content-disposition", "attachment; filename=\"" + filename + "\""); response.writefile(appdomain.currentdomain.basedirectory + "reports\\" + filename); response.end(); 

when file generated, control returned ajax calling page , there wan't show save file dialog based on ajax response , allow user download generated file. don't want save file on disk ajax called page , redirect ajax calling page file, because of popup blocker in ie. using jquery ajax calls:

$.ajax({       type:"post",      url: "ajaxreport.aspx",                    data:datastring,     success: function(data) {         //don't want use           // $('#redirectiframe').attr('src','reports/report.xlsx?cache='+math.random());         //want use data variable containing ajax response (bytes of report file) showing         //save dialog download file browser     }               });    

how this?

currently javascript can't access user's file system, meaning can't prompt users save file coming network stream.

in other words. you'll need redirect , write file stream http response , let user decide :)


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -