Jquery+ajax post请求如何下载文件流,
const xhr = new XMLHttpRequest();
xhr.open('POST', 'http://192.168.3.100:8999/sheng/importTemplate', true);
//定义responseType='blob', 是读取文件成功的关键,这样设置可以解决下载文件乱码的问题
xhr.responseType = "blob";
xhr.onload = () => {
//'\ufeff' 这个变量是定义字符集为utf-8, 防止中文乱码的问题。
// {type: 'application/msword'} 根据文档类型来定义这个type。MIMA type
const blob = new Blob(["\ufeff", xhr.response], {type: 'application/msword'});
const blobUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = blobUrl;
a.target = '_blank';
a.click();
}
xhr.send(null);
上面这种调用直接报错URL.createObjectURL is not a function