ARTICLE AD BOX
I have a simple interaction with javascript and PHP
First of all Javascript call the PHP routine:
async function genPdf() { try { const response = await fetch('genPdf.php', { method: 'POST', headers: { 'Content-Type': 'application/json' } }); const data = await response.text(); console.log("Server answer:", data); } catch (error) { console.log("Server answer:", "error"); } }second the PHP routine that answer:
<?php .....do something... $result = array("pdf" => "ok", "status" => true); header('Content-Type: application/json'); echo json_encode($result); ?>With this configuration all works fine.
But...there is a but..
In the PHP section where i wrote ...do something.. the routine built a PDF and at the end produce an output of the file created.
This things prevents the correct answer, so I 'm forced to decide if I want the PDF or the correct answer to javascript function waiting for a response.
Is there a way to fix this and have both features?
