使用AJAX调用显示PDF [英] Display PDF using an AJAX call

查看:224
本文介绍了使用AJAX调用显示PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示PDF通过AJAX调用(这是在服务器端产生并传递到客户端作为网络流)。我的code为如下:

I'm trying to display a PDF(which is created in the server side and pass to the client side as a web stream) through an AJAX call. My code is given below:

jQuery.ajax({
    type: "POST",
    processData: false,
    url: "aaaa.p?name=pdf",
    data: inputxml,
    contentType: "application/xml; charset=utf-8",
    success: function(data)
    {
      // here the data is the PDF stream i'm getting from the server side. 

    }
});

在'inputxml是包含输入参数服务器创建的PDF。在含有PDF流成功函数的数据。有没有什么办法打开的AJAX调用出做任何页面提交成功函数中的浏览器的PDF文件?在服务器端的PDF是不是身体产生也。高AP preciate你的帮助......

The 'inputxml' is containing input parameters for the server to create the PDF. and the 'data' in the success function containing PDF stream. Is there any way to open the PDF file on the browser inside the success function of the AJAX call with-out doing any page submit? In the server side the PDF is not physically generated also. Highly appreciate your help....

推荐答案

为什么要通过AJAX加载它?在您生成当你需要它的IFRAME你为什么不加载它。该标准的浏览器插件将显示它那么iframe内。

Why do you load it via AJAX? Why don't you load it in an IFRAME that you generate when you need it. The standard browsers plugin will display it then inside that Iframe.

$('#link').click(function(e) {
    e.preventDefault(); // if you have a URL in the link
    jQuery.ajax({
        type: "POST",
        processData: false,
        url: "aaaa.p?name=pdf",
        data: inputxml,
        contentType: "application/xml; charset=utf-8",
        success: function(data)
        {
            var iframe = $('<iframe>');
            iframe.attr('src','/pdf/yourpdf.pdf?options=first&second=here');
            $('#targetDiv').append(iframe);
        }
    });
}); 

这篇关于使用AJAX调用显示PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆