免费咨询合同模板下载,以下哪一项不属于seo对网站推广的作用,万网是做什么的,湖南省网站备案时间首先保证 改文件资源能够通过get请求或者 post请求拿到#xff0c;基于此基础上我们可以实现得知下载完成后的回调 代码如下
const getFileAndCallback (url, callback) {//定义执行作用域const that this;//首先 初始化一个原生ajax对象const xhr new XMLHttpReques…首先保证 改文件资源能够通过get请求或者 post请求拿到基于此基础上我们可以实现得知下载完成后的回调 代码如下
const getFileAndCallback (url, callback) {//定义执行作用域const that this;//首先 初始化一个原生ajax对象const xhr new XMLHttpRequest();//建立xhr请求xhr.open(GET, url, true);//定义xhr传输格式未blobxhr.responseType blob;//xhr回调函数xhr.onload function(){//接口成功响应if (this.status 200){const blob this.response;//定义fileReader对象const fileReader new FileReader();//使用fileReader原生api 读取xhr 存入fileReader对象fileReader.readAsDataUrl(blob);//监听fileReader的加载回调fileReader.onload async function(e){//兼容ie11的写法//ie 11对文件数据的存储转换api是window.navigator.msSaveBlob(this.response, 文件名/fileName) 或者 window.navigator.msSaveOrOpenBlob(this.response, 文件名/ fileName);if (window.navigator.msSaveOrOpenBlob){try {window.navigator.msSaveOrOpenBlob(this.response, 文件名/fileName)}catch(e){//日志记录解析失败的情况 理论上不会出现}}else{//ie11意外的文件下载用的是a标签downloadlet a document.createElement(a);a.download 文件名/fileName;a.href e.target.result;a.click();}};//此时已经下载完成 执行回调callback();}}}//实现方法如上