TCPDF不会在ajax调用下生成PDF文件 [英] TCPDF does not generate PDF file under ajax call

查看:89
本文介绍了TCPDF不会在ajax调用下生成PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php的TCPDF库生成和下载pdf文件。我使用javascript将参数传递给php到ajax:这些参数来自html表,我将其作为数组传输到PHP:这是我的Javascript代码的一部分:

I am trying to generate and download pdf file using the library TCPDF of php. I pass the parameters to php thru ajax using javascript: These parameters comes from html table, that I transfer to the PHP as an array :Here is the portion of my Javascript code:

var myTableArray = [];
    var nb = 0;

$("table#Table tr").each(function() {
    var arrayOfThisRow = [];
    var tableData = $(this).find('td');
    if (tableData.length > 0) {
        tableData.each(function() { arrayOfThisRow.push($(this).text()); });
        myTableArray.push(arrayOfThisRow);
        nb = nb +1;
    }
});

    jQuery.ajax({  
         type: "post",  
         url: "Generate_PDF.php",  
         data: {table:myTableArray, Line :nb },
         success: function(count){  
             alert("done"); 
         }  
    }); 



这里是PHP代码:


And here is the PHP Code:

function fetch_data()  
 {
$aDataTableDetailHTML = ' ';
     $count = $_POST['Line'];
      $line = 0;
      $row = 0;
      for($line; $line < $count; $line++)
      {
          for ($row =0; $row < 2; $row++)
          {
             If ($row == 0)
                {
    $aDataTableDetailHTML .= '<tr><td>'.$_POST['table'][$line][$row].'</td>';
                } enter code here
                else
                {
    $aDataTableDetailHTML .= '<td>'.$_POST['table'][$line][$row].'</td></tr>'; 
                }
          }
      }
      $aDataTableDetailHTML1 = '<tr><td> introduction 123 </td><td> temps zero</td></tr>';
    return $aDataTableDetailHTML;





- > Network-> preiew我看到pdf文件的确如此没有生成,我看到一个奇怪的长文本开头:



in the chrome consol ->Network->preiew I see that the pdf file does not get generated, and I see a strange long text that starts with:

%PDF-1.7
%âãÏÓ
7 0 obj
<< /Type /Page /Parent 1 0 R /LastModified (D:20170513141422+02'00') /Resources 2 0 R



这个奇怪的文字太长了它结束了with:


This strange text is too long and it ends with:

0000006871 00000 n 
trailer
<< /Size 12 /Root 11 0 R /Info 9 0 R /ID [ <f7adf2ceab2607d2e2cecc277437d8cd> <f7adf2ceab2607d2e2cecc277437d8cd> ] >>
startxref
7080
%%EOF





任何想法人员......!?谢谢



我尝试了什么:



我试过我可以......请在我的问题中看到解释,我感到自由如果你需要更多的澄清。



Any Idea folks...!? Thanks

What I have tried:

I have Tried all I could...please see the explanation in my question, I feel free If you need any more clarifications.

推荐答案

(table#Table tr)。每个( function(){
var arrayOfThisRow = [];
var tableData =
("table#Table tr").each(function() { var arrayOfThisRow = []; var tableData =


(this).find('td');
if(tableData .length> 0){
tableData.each(function(){arrayOfThisRow.push(
(this).find('td'); if (tableData.length > 0) { tableData.each(function() { arrayOfThisRow.push(


(this).text());});
myTableArray.push(arrayOfThisRow);
nb = nb +1;
}
});

jQuery.ajax({
类型:post,
url:Generate_PDF.php,
data:{table:myTableArray,Line:nb} ,
成功:函数(计数){
alert(done);
}
});
(this).text()); }); myTableArray.push(arrayOfThisRow); nb = nb +1; } }); jQuery.ajax({ type: "post", url: "Generate_PDF.php", data: {table:myTableArray, Line :nb }, success: function(count){ alert("done"); } });



这里是PHP代码:


And here is the PHP Code:

function fetch_data()  
 {


这篇关于TCPDF不会在ajax调用下生成PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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