ajax异步无法返回下载文件
可以通过添加from表单隐藏域的方式实现。
另外也想过直接js调用excell插件来生成文件学艺不精放弃了。
[b]Require:[/b]
[b]Action:[/b]
可以通过添加from表单隐藏域的方式实现。
另外也想过直接js调用excell插件来生成文件学艺不精放弃了。
[b]Require:[/b]
$(".feedback.button").click(function(){
var form = $("<form>");
form.attr('style', 'display:none');
form.attr('target', '');
form.attr('method', 'post');
form.attr('action', '<%= download_feedback_crm_products_path%>');
var input1 = $('<input>');
input1.attr('type', 'hidden');
input1.attr('name', 'item');
input1.attr('value', "<%= CGI.escape(@result[:data].to_json) %>");
$('body').append(form);
form.append(input1);
form.submit();
form.remove();
});
[b]Action:[/b]
# 下载sku 反馈信息
def download_feedback
result = CGI.unescape(params[:item])
data = JSON.parse(result)
file = Spreadsheet::Workbook.new
list = file.create_worksheet :name => "test"
list.row(0).concat ["CAS No.", "Product Name", "Assay/Purity", "In Stock (yes/no)", "Note","Result"]
data.each_with_index { |report, i|
list.row(i+1).concat report.values
}
xls_report = StringIO.new
file.write xls_report
send_data xls_report.string, :type => 'text/xls', :filename => "wait_shipments.xls"
end