-
-
Save amendoncabh/6942d0ddab1d6749c7de1ff180473f8c 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"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment