I have a PHP script that allows a user to download a file. It works fine if I create a standard button on my form and, on post back, call the PHP script. However, I'm trying to have the button call some Javascript that then uses AJAX to call the PHP script. I don't get any errors but the file doesn't download.
//JAVASCRIPT
<script type="text/javascript">
function downloadForm()
{
var data = {ipAddress : "<?php echo $ipAddress; ?>", userID : "<?php echo $userID; ?>"};
jQuery.ajax({
url: "/download-form-internal.php",
type:'POST',
data: data,
dataType: 'html',
success: function(result){
},
});
}
</script>
//PHP CODE SNIPPET
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.$FILENAME);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_clean();
flush();
echo $fileToDownload;
exit();
Thanks for any help!