Handle file download from ajax post

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

    As others have stated, you can create and submit a form to download via a POST request. However, you don't have to do this manually.

    One really simple library for doing exactly this is jquery.redirect. It provides an API similar to the standard jQuery.post method:

    $.redirect(url, [values, [method, [target]]])
    

提交回复
热议问题