Created
September 20, 2012 08:37
-
-
Save vivisidea/3754693 to your computer and use it in GitHub Desktop.
download file using jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.download = function(url, data, method){ | |
if( url && data ){ | |
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] +'" />'; | |
}); | |
//send request | |
jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>') | |
.appendTo('body').submit().remove(); | |
}; | |
}; | |
// how to use | |
$("#exportbtn").click(function(){ | |
$.download(prefix+"/export.html", getparams(), "get"); | |
}); |
getparams is not defined
getparams is not defined
it depends on your implementation, get whatever params for download you need.
getparams is not defined
... and it was 9 years ago, people still using jQuery today?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ghjgjghjkhjklhjkgf