javascript - Output file PDF with Jquery -
javascript - Output file PDF with Jquery -
i need help or advice output file pdf jquery . have problem output file because pdf file don't out . script jquery , html:
<script> $("#msg").hide(); $("button").click(function() { var subject = $("#subject").val(); var client = $("#client").val(); $.ajax ({ url: "http://localhost/report/fpdf_report.php", type: "post", data: { subject: subject, client: client }, success: function(data) { $("#msg").html(data); $("#msg").fadein("slow").delay(2000); }, error: function(xhr) { alert(xhr+"error"); } }); }); </script>
<input type="text" id="subject" /> <input type="text" id="client" /> <input type="text" id="client" /> <button>pdf</button> <br /> <div id="msg"></div>
so script php convert pdf :
<?php $subject = $_post['subject']; $client = $_post['client']; require ('fpdf/fpdf.php'); $pdf = new fpdf(); $pdf -> addpage(); $pdf -> setfont('arial','b',20); $pdf -> cell(40,10,$subject); $pdf -> cell(50,20,$client); $pdf -> output(); ?>
the result of php script pdf file, can't utilize div.
you'll need object element like:
<object id="msg" type="application/pdf" data="test1.pdf"> unable open pdf file. </object>
and you'll need save pdf result on file doing this:
$filename = '/path/of/my/file/test.pdf'; $pdf -> output($filename, 'f'); echo $filename;
so jquery need alter de info attribute of object element, result of ajax post (the result name of pdf file).
$.ajax ({ url: "http://localhost/report/fpdf_report.php", type: "post", data: { subject: subject, client: client }, success: function(data) { $("#msg").attr("data", data); }, error: function(xhr) { alert(xhr+"error"); } });
javascript php jquery pdf
Comments
Post a Comment