0

I have form in website.php file. After user submits form I want to start download PDF with user data by mPDF extension. However when user submits form nothing happens. Only some gibberish appears in browser console.

The form data is sent to website.php using jquery's $.ajax() function. The formData is recieved in PHP, but the download won't start. Instead I recieve console full of mPDF's data. Now I don't care about user's formData, I just want to make mPDF's download work.

My PHP code in website.php:

if(array_key_exists("formData", $_POST)) {
    $mpdf = new \Mpdf\Mpdf();
    $mpdf->WriteHTML('<h1>Hello world!</h1>');
    $mpdf->Output('MyPDF.pdf', 'D'); 
}
  • your basically trying to download a file via Ajax, which is problematic. easy option is is to just not use ajax. –  Jan 28 '19 at 21:48
  • take a look at this https://stackoverflow.com/questions/6668776/download-file-through-an-ajax-call-php, looks like you can specify the correct content type on the response and hack it work, although its not recommended. – Orlando P. Jan 28 '19 at 22:50

0 Answers0