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 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改