How can I download a word file with PhpWord and Ajax


I have a problem to download files with Ajax and PHP, when I open directly my file .php if I download the file, but when I call it from Ajax it only generates the file and does not download it,

My Ajax function:

$.ajax({ url:"php/word_calendario.php", method:"POST", data:{ "desde": desde, "hasta": hasta }, success: function (data) { $('#calendar').fullCalendar('refetchEvents'); UIkit.modal("#modal-reportes", {bgclose: false, keyboard:true}).hide(); UIkit.notification( { message: data, status: 'success', pos: 'top-center', timeout: 5000 } ); }, complete: function(data){ } })

and my PHP:

require_once '../vendor/phpoffice/phpword/bootstrap.php';
use PhpOffice\PhpWord\Style\Language;
// nuevo documento
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$myTextElement = $section->addText('TEXTO DE PRUEBA');

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');

echo file_get_contents('helloWorld.docx');
asked by arglez35 13.11.2018 в 00:08

0 answers