dongquan0024 2010-07-23 17:08
浏览 457

使用Jquery从字符串下载pdf文件

All,

I have a PHP5 application written with Zend Framework and MVC. On my home page, I want to incorporate the functionality to download a dynamically generated pdf file. The way this is done is:

  1. User clicks "download file" link.
  2. On Click, an AJAX call occurs to a PHP controller, which takes the form data, generates the pdf and returns it as a string.
  3. My javascript function now has the pdf string.
  4. How can I display the user an "Open/Save" dialog to download the pdf file from javascript?

I have the following code:

<script type="text/Javascript">
   $('#dlcontent').click(function(e) {
      $.ajax({
                type: 'POST',
                url: "/downloads/dlpolicies",
                data:  $("#frmMyContent").serialize(),
                cache: false,
                dataType: "html",
                success: function(html_input){
                    alert(html_input);  // This has the pdf file in a string.
                    //ToDo: Open/Save pdf file dialog using this string..
                }
            });
});
</script>

Thanks

  • 写回答

3条回答

  • down101102 2010-07-23 17:11
    关注

    The simplest way of doing it is open a new window with URL to pdf string.

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题