Handle file download from ajax post

前端 未结 20 2643
心在旅途
心在旅途 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:12

    Create a form, use the POST method, submit the form - there's no need for an iframe. When the server page responds to the request, write a response header for the mime type of the file, and it will present a download dialog - I've done this a number of times.

    You want content-type of application/download - just search for how to provide a download for whatever language you're using.

提交回复
热议问题