Handle file download from ajax post

前端 未结 20 2640
心在旅途
心在旅途 2020-11-21 05:46

I have a javascript app that sends ajax POST requests to a certain URL. Response might be a JSON string or it might be a file (as an attachment). I can easily detect Content

20条回答
  •  情话喂你
    2020-11-21 06:19

    To get Jonathan Amends answer to work in Edge I made the following changes:

    var blob = typeof File === 'function'
        ? new File([this.response], filename, { type: type })
        : new Blob([this.response], { type: type });
    

    to this

    var f = typeof File+"";
    var blob = f === 'function' && Modernizr.fileapi
        ? new File([this.response], filename, { type: type })
        : new Blob([this.response], { type: type });
    

    I would rather have posted this as a comment but I don't have enough reputation for that

提交回复
热议问题