Is it possible to return 2 different types by an AJAX request?
I created a form with method post. The PHP file creates a PDF file what is returned to the JavaScript file and is automatically downloaded.
But I want also return an array to the same JavaScript file with messages like errors or a notice.
Can I do this in one call or is there a second call needed?
var form = event.target;
var formData = new FormData(form);
fetch(url,{
method: 'post',
body: formData
}).then(response => response.blob()).then(response => {
const blob = new Blob([response], {type: 'application/pdf'});
const downloadUrl = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = downloadUrl;
a.download = formData.getAll("invoicenumber")+".pdf";
document.body.appendChild(a);
a.click();
});
PHP
$createPdf = new CreatePdf;
$response['msg'] = 'PDF is created!';
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($response);