POST to server, receive PDF, deliver to user w/ jQuery

前端 未结 7 1502
逝去的感伤
逝去的感伤 2020-11-27 04:01

I have a link that the user clicks to get a PDF. In jQuery, I create a POST ajax call to the server to get the PDF. The PDF comes to me with the correct content headers et

7条回答
  •  爱一瞬间的悲伤
    2020-11-27 04:26

    Take a look at - jQuery Plugin for Requesting Ajax-like File Downloads

    The whole plugin is just about 30 lines of code (including comments).

    The call is fairly similar to jquery ajax call.

    $.download('/export.php','filename=myPDF&format=pdf&content=' + pdfData );
    

    Ofcourse, you have to set the content-type and Content-Disposition headers on the server side as you would for any such download.

    In java I would do something like this

    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename="exported.pdf");
    

提交回复
热议问题