This question is a question that I asked a few days ago regarding a similar type of site / problem.
My solution was: (1) in Javascript, to set a cookie, and then call the PHP script using location.href = ...;
(not AJAX), and then (2) provide the PHP script with access to the cookie to determine the desired type of report, and then an echo form that asks the user to download the file using the correct headers. PHP was something like this:
header("Content-type: application/vnd.ms-word"); header("Content-Disposition: attachment;Filename=test.doc"); echo "<html>"; echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">"; echo "<body>"; echo "Testing-2-3!"; echo "</body>"; echo "</html>";
Failed to get what I wanted to use AJAX, because AJAX never allows you to request a user.
You can use this method to do something similar, but in your case you will create a PDF file, not a .doc file (or download the one that is pre-prepared).
One of the advantages of this method, of course, is that it does not require page reloading.
source share