1 jQuery.download = function(url, data, method) {
2 //url and data options required
6 //data can be string of parameters or array/object
7 data = typeof data == 'string' ? data : jQuery.param(data);
8 //split params into form inputs
9 var form = jQuery('<form action="'+ url +'" method="'+ (method||'post') +'"></form>');
10 jQuery.each(data.split('&'), function(){
11 var pair = this.split('=');
12 var input = jQuery('<input type="hidden"/>');
13 input.attr('name', decodeURIComponent(pair[0]));
14 input.val(decodeURIComponent(pair[1]));
18 form.appendTo('body').submit().remove();