gpt4 book ai didi

javascript - 这个xhr请求在axios中怎么写?

转载 作者:行者123 更新时间:2023-12-05 02:58:07 25 4
gpt4 key购买 nike

<分区>

如何使用 Axios 调用而不是 XMLHttpRequest 编写以下代码?

var xhr = new XMLHttpRequest;
xhr.open("POST", "/attachments", true);
/*open an ajax request.*/

xhr.upload.onprogress = function(event) {
var progress = event.loaded / event.total * 100;
attachment.setUploadProgress(progress);
};

xhr.onload = function() {
if (xhr.status === 201) {
setTimeout(function() {
var url = xhr.responseText;
attachment.setAttributes({ url: url, href: url });
}, 30)
}
};

attachment.setUploadProgress(10);

setTimeout(function() {
xhr.send(attachment.file);
}, 30)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com