为什么我的 XMLHttpRequest 进度控制台日志没有显示?

问题描述 投票:0回答:1

控制台未记录文件上传的进度。为什么?

这是我的代码:

const xhr = new XMLHttpRequest();
    
xhr.open('POST', apiUrl);

xhr.upload.addEventListener("progress", function(e){
    console.log(e.loaded/e.total)      
})

xhr.onload = () => {
    const response = JSON.parse(xhr.response);
    console.log(response);
    // ... do something with the successful response
};
        
xhr.send(formData);
javascript ajax react-native file-upload xmlhttprequest
1个回答
0
投票

您的

apiUrl
响应必须具有 HTTP 响应标头
Content-Length
。如果没有,则无需计算。

© www.soinside.com 2019 - 2024. All rights reserved.