Last active
March 1, 2020 08:57
-
-
Save renzhezhilu/8ee4316319c39250777cddf235aac363 to your computer and use it in GitHub Desktop.
[fetch浏览器] #请求
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://developer.mozilla.org/zh-CN/docs/Web/API/Body | |
fetch(`https://xxxxxx`) | |
.then(x=>{ | |
return x.json() | |
//x.text() | |
//x.blob() | |
//x.formData() | |
//x.arrayBuffer() | |
}).then(d=>{ | |
console.log(d) | |
}) | |
// gbk编码,fetch出来的结果乱码了 | |
fetch('http://tieba.baidu.com') | |
.then(res=> res.blob()) | |
.then(blob => { | |
var reader = new FileReader(); | |
reader.onload = function(e) { | |
var text = reader.result; | |
console.log(text) | |
} | |
reader.readAsText(blob, 'GBK') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment