douyan5481 2014-09-02 20:37
浏览 74

使用JQuery或JavaScript自动提交

I need to send a var which contains html code.

I have a file with html code, and I read it and put that HTML code in a var with

ob_start();
$output = ob_get_contents();
ob_end_clean();

I tried to send it via GET with header(location:); but I get the error (headers already sent). so I want to send it via JQuery or JavaScript.

I tried to do this

var output = $('#out').text(); 
        $.post('../tcpdf/examples/polizaPDF.php',{output:output})
    .done(function(data) 
    {
        console.log($.trim(data));
    });

But I need to stay in the page "polizaPDF.php".

What do I do in polizaPDF.php? I print the var output which contains the html code. So I can get a PDF in the browser. I use tcpdf to print the pdf.

Can anyone help me or give me some advice to do this?

  • 写回答

2条回答 默认 最新

  • dpcnm2132 2014-09-02 20:43
    关注

    You might want to check the documentation on Ajax calls. Here's an example on how to pass data to a file :

    $.ajax({
        type: "GET",
        url: "../tcpdf/examples/polizaPDF.php",
        data: { output: output }
    })
    .done(function(data) {
        console.log($.trim(data));
    });
    

    Then on your polizaPDF.php you now have access to the php variable $_GET['output']

    评论

报告相同问题?

悬赏问题

  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))