前端跨域经验
栏目: JavaScript · 发布时间: 6年前
内容简介:重点: 1.简单请求&复杂请求;2.cookiecanvas getImageData&toDataURL 也有跨域问题
接口跨域
jsonp
window.name + iframe
domain(主域相同)
cors
重点: 1.简单请求&复杂请求;2.cookie
图片跨域
canvas getImageData&toDataURL 也有跨域问题
解决方法:cors
a标签 download 跨域失效
解决思路: 通过fetch或者xhr下载下来,转为blob,再createObjectURL
注意:诺通过axios发请求下载文件出错,具体原因未查
const a = document.createElement('a');
const url = "http://*******.zip";
const filename = "文件名称";
const xhr = new XMLHttpRequest();
xhr.open('get', url);
xhr.responseType = 'blob';
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
const blob = new Blob([xhr.response]);
a.href = URL.createObjectURL(blob);
a.download = filename;
a.click();
}
};
xhr.send();
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- HIS 系统前端重构经验
- 中专毕业生的前端面试经验分享
- 记一次忏悔的前端面试经验(Vue 双向绑定原理)
- 前端手札——vue组件vue-tinymce开发经验分享
- web前端开发学习经验分享——css,js入门篇
- 每天学习2小时,17年前端经验分享,让你前端之路不再迷茫
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Machine Learning in Action
Peter Harrington / Manning Publications / 2012-4-19 / GBP 29.99
It's been said that data is the new "dirt"—the raw material from which and on which you build the structures of the modern world. And like dirt, data can seem like a limitless, undifferentiated mass. ......一起来看看 《Machine Learning in Action》 这本书的介绍吧!