针对ajax请求,返回二进制流的形式,实现文件下载
var options = {
"url": "/haha/attachment/download.do?eventid=" + file.oid + "&token=" + localStorage.getItem("token"),
"method": 'post'
}
var config = $.extend(true, {
method: 'get'
}, options);
var $iframe = $('<iframe id="down-file-iframe" />');
var $form = $('<form target="down-file-iframe" method="' + config.method + '" />');
$form.attr('action', config.url);
for (var key in config.data) {
$form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" />');
}
$iframe.append($form);
$(document.body).append($iframe);
$form[0].submit();
$iframe.remove();