生成PDF swal ajax发布到php

时间:2019-03-27 10:25:43

标签: php ajax

我正在使用swal按钮下载pdf。当我回显/打印得到结果的数据时,数据将发布到php文件中。但是在链接时将不会生成pdf函数pdf。

swal({  title: "Download",   
        text: "Here,You Can Download PDF Invoice",   
        type: "warning",   
        showCancelButton: true,
        confirmButtonText: "Download it!",   
        cancelButtonText: "Close",   
        closeOnConfirm: false,   
        closeOnCancel: false }, 
        function(){
                   saveJsonObj = {customer_number: urlParameter,
                                  agent_id: "",
                                  operator_id: "<?php echo $Operator_id; ?>",
                                  mobile_number:$('#mobile_number').val(),
                                  mode_of_payment: "1",
                                  balance_amount: bal_amt,
                                  amount_collected: amt_cltd,
                                  payment_amount: pay_amt,
                                  tax_amount: $('#tax_amount_t').text(),
                                  collection_date: "<?php echo $dateTime; ?>",
                                  tran_id: tranId,
                                  rebate: rebate_amt
                     };
  var finData = JSON.stringify(saveJsonObj);
   $.ajax({
           type:'post',
           url:'download/download_pdf.php',
           data: {myData:finData},
           success:function (results) {
           var url = window.URL.createObjectURL(results);
           a.href = url;
           a.download = 'myfile.pdf';
           a.click();
           window.URL.revokeObjectURL(url);
          }
        })
    });




<?php
    require_once('../../auth_admin.php');
    require("../fpdf/fpdf.php");
    include('../../dbConnect.php');

    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();
?>

当我单击生成pdf的swal按钮时

0 个答案:

没有答案