473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

TCPDF does not generate PDF file under ajax call

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:

Expand|Select|Wrap|Line Numbers
  1. var myTableArray = [];
  2.     var nb = 0;
  3.  
  4. $("table#Table tr").each(function() {
  5.     var arrayOfThisRow = [];
  6.     var tableData = $(this).find('td');
  7.     if (tableData.length > 0) {
  8.         tableData.each(function() { arrayOfThisRow.push($(this).text()); });
  9.         myTableArray.push(arrayOfThisRow);
  10.         nb = nb +1;
  11.     }
  12. });
  13.  
  14.     jQuery.ajax({  
  15.          type: "post",  
  16.          url: "Generate_PDF.php",  
  17.          data: {table:myTableArray, Line :nb },
  18.          success: function(count){  
  19.              alert("done"); 
  20.          }  
  21.     });
And here is the PHP Code:
Expand|Select|Wrap|Line Numbers
  1. function fetch_data()  
  2.  {
  3. $aDataTableDetailHTML = ' ';
  4.      $count = $_POST['Line'];
  5.       $line = 0;
  6.       $row = 0;
  7.       for($line; $line < $count; $line++)
  8.       {
  9.           for ($row =0; $row < 2; $row++)
  10.           {
  11.              If ($row == 0)
  12.                 {
  13.     $aDataTableDetailHTML .= '<tr><td>'.$_POST['table'][$line][$row].'</td>';
  14.                 } enter code here
  15.                 else
  16.                 {
  17.     $aDataTableDetailHTML .= '<td>'.$_POST['table'][$line][$row].'</td></tr>'; 
  18.                 }
  19.           }
  20.       }
  21.       $aDataTableDetailHTML1 = '<tr><td> introduction 123 </td><td> temps zero</td></tr>';
  22.     return $aDataTableDetailHTML;
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<
===============================================
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
May 13 '17 #1
5 4084
Dormilich
8,658 Expert Mod 8TB
and I see a strange long text that starts with:
that strange long text is your PDF file!
May 15 '17 #2
@Dormilich
Do you know why it doesnt display the pdf ?
And if you know the name of that format ? if there is one.
Jun 14 '17 #3
Dormilich
8,658 Expert Mod 8TB
Do you know why it doesnt display the pdf ?
because console->Network->preview considers everything text.
Jun 15 '17 #4
Yeah i know but it should be generated in the browser ?
Jun 15 '17 #5
Dormilich
8,658 Expert Mod 8TB
your server creates the PDF, not the browser.
Jun 15 '17 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Grzegorz Smith | last post by:
Hi everyone. Does anyone know is it possible to check if ajax call was redirect? i mean I connect by Ajax to one URL but I'm redirected to other url. Is there a way to check that my request was...
2
by: Zeba | last post by:
Hi guys! I'm new to JS / Ajax; I've been trying to do an Ajax call to my Webservice ( I'm using C# for code-behind). I'm not using any of the libraries available. I am sending my CustID to the...
3
by: wendallsan | last post by:
Hi All, I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have: I have a custom class named Default_county_init_data that, upon initialization makes...
3
by: KDawg44 | last post by:
Hi, I would like a verification image for new sign ups on a website. Is there a way to call the PHP script through an AJAX call and have the image passed back and then display? Is there a way...
5
RamananKalirajan
by: RamananKalirajan | last post by:
Hi guys, I am having a problem in Prototypejs AJAX, I am triggering the AJAX call and in the option i am using like the folowing code: new Ajax.Request(connection.url, { method:...
9
Claus Mygind
by: Claus Mygind | last post by:
I am having trouble escaping the & in a JSON.stringfy() ajax call. I don't even know if I am stating the problem correctly here. In my app I have linked json2.js from http://www.JSON.org/json2.js...
5
by: samarinder | last post by:
I am displaying the results by iterating the list in div tag say "results" in my case.For refining of search i am using ajax call. But when i am getting response back from this below snippet ...
1
by: Ess Zee | last post by:
I need to get the "root url" for an Ajax call in my html file $.ajax({ type: "GET", url: "json.php", data: "url=" + "" + "myxml.xml", });
0
by: varunkumarid | last post by:
I have tried to download the file from the server through the webmethod but it has not work for me. my code as below public static string GetServerDateTime(string msg) { String result =...
1
by: kinjalkhamar | last post by:
I needed to validate textbox value from database using ajax call. i have inluded below in jsp file <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> i have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.