We have an interesting way of doing ajax here at work with a custom in house framework, essentially in some javascript function some where I do:
CT.postSynch('report/index/downloadProjectsInProgress', {}, function(data){
});
This tells ajax to look for a module called Report
, a controller called Index
and a action called ajazDownloadProjectInprogress
I wrote a function ajazDownloadProjectInprogress, which all it does is create a simple PDF based on some data I am getting back. in that function I have the following (using DOMPDF) like this:
$dompdf = new DOMPDF();
$content = $this->raw('./report.header','./projectsInProgressReport','./report.footer');
$dompdf->load_html($content);
$dompdf->render();
$dompdf->output();
header('Pragma:');
header('Cache-Control: private,no-cache');
return $dompdf->stream("Structure Report - ProgressReports.pdf", array('Attachment' => 1));
all I'm doing here is grabbing some contents based on the way we render views as either html or raw data, and attempting to stream the pdf back through ajax.
In the above code, where I showed you how we deal with ajax calls, I did:
CT.postSynch('report/index/downloadProjectsInProgress', {}, function(data){
return data;
});
Now the network tab shows me:
%PDF-1.3
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R >>
endobj
2 0 obj
<< /Type /Outlines /Count 0 >>
endobj
3 0 obj
<< /Type /Pages
/Kids [6 0 R
]
/Count 1
/Resources <<
/ProcSet 4 0 R
/Font <<
/F1 8 0 R
/F2 9 0 R
>>
/XObject <<
/I1 10 0 R
/I2 11 0 R
Thats just a sample of whats returned back .... If I wasn't doing this through ajax and I just made a direct call to this action an actual PDF would download with my desired contents.
Any one know what your suppose to do to download a PDF through an ajax call? I know ajax it's self will not download the file - but i set up everything such that the function should just start the download process.