Fetch api, Retrieve response data

0

I have a code in javascript that sends an id by POST, to a php file (vs 7.2.9) that consults with sql to a DB, and I need the html code it generates to make a report with dompdf

Javascript code

let cedu = snapshot.val().cedula;
                fetch(url ='./php/views/certificacion_afiliacion_trabajador.php', {
                    method: 'POST',
                    body: JSON.stringify({'cedula': cedu}),
                    redirect: 'follow',
                }).then(function (response) {
                    if (response.ok)
                    {
                        return response.text();
                    }
                    else{
                        throw "Error en la llamada ajax";
                    }
                }).then(function (text) {
                    console.log(text);
                }).catch(function (err) {
                    console.log(err);
                })

Browser response

That HTML code that I generate I would like to receive as a variable in this php file

use Dompdf\Dompdf;
require_once("./../../../../libs/dompdf/autoload.inc.php");
var_dump(file_get_contents("php://input"));
$arrayData = (file_get_contents("php://input"));
$arrayCodigo =json_decode($arrayData);
foreach ($arrayCodigo as $index => $fila){
    $html = $fila;
}
$html =""; // Aqui quiero recibir el codigo HTML para renderizarlo como pdf
$pdf = new DOMPDF();
$pdf-> setPaper("A4", "portrait");
$pdf->loadHtml($html);
$pdf->render();
    
asked by Marteen Munevar 05.11.2018 в 22:59
source

0 answers