weixin_33737774 2012-05-16 21:36 采纳率: 0%
浏览 69

jQuery Ajax:pdf响应

I have a link and when user click on it, then he get a PDF. In jQuery, I create a POST ajax call to the server to get the PDF. The response is a PDF, with correct content headers etc that would normally cause the browser to open the Reader plugin, or allow the user to save the PDF. But in my case, this is not working. Is there any way to set data content type, or set content type to PDF?

My ajax call:

$('#sf_getpdf').click(function() {

 $.ajax({    //create an ajax request to load_page.php

        type: "POST",

        url: "index.php?route=sale/order/superfaktura_getpdf&token=<?php echo $token; ?>",

        data: 'invoice_id=<?php echo $invoice_id; ?>&sf_token=<?php echo $sf_token ?>',  //with the page number as a parameter

        dataType: "text",   //expect html to be returned


        success: function(msg){



            if(parseInt(msg)!=0)    //if no errors

            {

            document.write(msg)
            }

        }

    });

});

Firebug, response: Firebug

Response in browser...

response in browser

I already tried to set content-type in server, without success:

content-type in server

Edit: The Ajax is not needed, to do this.

<a id="adr_stitok" target="_blank" href="index.php?route=sale/order/superfaktura_getpdf&token=<?php echo $token; ?>&invoice_id=<?php echo $invoice_id; ?>&sf_token=<?php echo $sf_token ?>" >Download</a></td>

Will do the thing.

  • 写回答

2条回答 默认 最新

  • weixin_33725515 2012-05-16 21:41
    关注

    It won't work because AJAX calls do NOT fetch PDF and load it inside the browser. That's why it's called XMLHttpRequest.. it only exchanges just text!

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型