怎么上传一个掘金gif头像
2020-12-29 18:28
标签:stat response for 12月 reload location ready function const 想不想拥有一个掘金gif头像? 现在是2020年12月24日,估计以后版本更新会有些参数要改一下。顺便祝大家平安夜快乐(_) 现在看下你的新头像吧~~ 怎么上传一个掘金gif头像 标签:stat response for 12月 reload location ready function const 原文地址:https://www.cnblogs.com/huan021/p/14183003.html
const input = document.createElement(‘input‘)
input.type = ‘file‘
input.style = ‘position: fixed; left: 0; top: 0; z-index: 999;‘
document.body.prepend(input)
(function() {
let formdata = new FormData();
formdata.append(‘aid‘, "你的appid");
formdata.append(‘avatar‘, input.files[0]);
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText)
const url = JSON.parse(xhr.responseText).data.web_uri
let formdata = new FormData();
formdata.append(‘aid‘, "你的appid");
formdata.append(‘avatar‘, url);
const xhr2 = new XMLHttpRequest();
xhr2.onreadystatechange = function() {
if (xhr2.readyState == 4 && xhr2.status == 200) {
location.reload()
}
};
xhr2.open(‘POST‘, ‘https://juejin.cn/user/update/user_info/‘);
xhr2.send(formdata)
}
};
xhr.open(‘POST‘, ‘https://juejin.cn/user/update/upload_avatar/‘);
xhr.send(formdata)
})()
下一篇:log4net配置