├── .repo-rt ├── README.md └── jQuery.download.js /.repo-rt: -------------------------------------------------------------------------------- 1 | RETIRED 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :warning: This project is archived and the repository is no longer maintained. 2 | 3 | jQuery-File-Download 4 | ==================== 5 | 6 | One issue we have not yet seen addressed is the Ajax’s inability to receive a response in any form but text. Since it is now common for web applications to offer options for exporting your data in desktop app formats — such as .doc or .xls — we wrote a jQuery plugin to facilitate requests from the front end that result in a file for download. The plugin does not actually use Ajax, but its syntax follows the conventions of jQuery's native Ajax functions, making it a natural addition to our jQuery toolset. 7 | -------------------------------------------------------------------------------- /jQuery.download.js: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------- 3 | * jQuery-Plugin - $.download - allows for simple get/post requests for files 4 | * by Scott Jehl, scott@filamentgroup.com 5 | * http://www.filamentgroup.com 6 | * reference article: http://www.filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/ 7 | * Copyright (c) 2008 Filament Group, Inc 8 | * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses. 9 | * -------------------------------------------------------------------- 10 | */ 11 | 12 | jQuery.download = function(url, data, method){ 13 | //url and data options required 14 | if( url && data ){ 15 | //data can be string of parameters or array/object 16 | data = typeof data == 'string' ? data : jQuery.param(data); 17 | //split params into form inputs 18 | var inputs = ''; 19 | jQuery.each(data.split('&'), function(){ 20 | var pair = this.split('='); 21 | inputs+=''; 22 | }); 23 | //send request 24 | jQuery('
') 25 | .appendTo('body').submit().remove(); 26 | }; 27 | }; 28 | --------------------------------------------------------------------------------