Diskuze: jQuery Plugin jquery.fileDownload.js
Zobrazeno 2 zpráv z 2.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
Tak jsem to nakonec vyřešil tímto pluginem využívající action formu a hidden inputy pro odeslání parametrů, např. pro PHP:
/*
* --------------------------------------------------------------------
* jQuery-Plugin - $.download - allows for simple get/post requests for files
* by Scott Jehl, [email protected]
* http://www.filamentgroup.com
* reference article: http://www.filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/
* Copyright (c) 2008 Filament Group, Inc
* Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
* --------------------------------------------------------------------
*/
jQuery.download = function(url, data, method){
//url and data options required
if( url && data ){
//data can be string of parameters or array/object
data = typeof data == 'string' ? data : jQuery.param(data);
//split params into form inputs
var inputs = '';
jQuery.each(data.split('&'), function(){
var pair = this.split('=');
inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />';
});
console.log(inputs);
//send request
jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
.appendTo('body').submit().remove();
};
};
s jednoduchým voláním jQuery:
$.download('download.php','filename=report.pdf');
volající toto PHP:
<?php
$file = 'temp/report.pdf';
ob_clean();
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.basename($file));
readfile($file);
exit();
?>
Tak třeba to někomu pomůže.
Standa
Zobrazeno 2 zpráv z 2.