How to submit it to php via ajax, generate pdf and download it through tcpdf?

1. The front-end ajax submits data to php
_ html as the content to generate pdf (html code)
_ name as the file name to generate psdf

$.ajax({
              type: "POST",
              dataType: "json",
              url: "{:url("api/pdf/create")}",
              data: { "html": _html,"name":_name},
              success:function(res){

              }
            });

2. Backend php (url:api/pdf/create)
Controller file code is as follows (using tcpdf):

$tcpdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, "UTF-8", false);
        $tcpdf->SetFont("msyh", "", 10, "", true);
        $tcpdf->SetTitle($name);
        $tcpdf->AddPage();
        $tcpdf->writeHTML($html);
        $tcpdf->lastPage();
        $tcpdf->Output($name.".pdf","D");
        exit();

description: if you submit it to php through ajax to generate, F12, click network, click api/pdf/create, click response to get the string of pdf, as shown in figure

question: how to click the button, trigger ajax, submit the information to php, and pop up the download box of pdf?

Jun.30,2022

Jump directly to the controller to download

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e8eb4e-46fd5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e8eb4e-46fd5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?