ajax 文件下载,实际上就是模拟表单提交,代码如下:

function download(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]+'" />';

});

//send request

jQuery('<form action="'+ url +'" method="'+(method||'post')+'">'+inputs+'</form>')

.appendTo('body').submit().remove();

};

};

  

相关文章:

  • 2021-11-12
  • 2022-02-24
  • 2021-07-02
  • 2021-09-01
  • 2022-02-18
  • 2021-12-24
猜你喜欢
  • 2021-05-27
  • 2021-12-27
  • 2021-10-11
  • 2021-07-26
  • 2021-09-22
  • 2022-02-12
  • 2021-06-26
相关资源
相似解决方案