Loading

fetch请求示例

fetch(url + 'get_progress/', {
            method: 'GET'
        }).then(response => {
            if (response.ok) {
                return response.json()
            } else {
                throw new Error('获取进度失败')
            }
        }).then(data => {
            // 接收数据
            let progress = data.data.progress
            // 保留一位小数
            progress = Math.round((progress * 10) / 10)
            // 实时更新进度条
            progressBar.style.width = (progress).toString() + '%'
            progressPercent.innerText = (progress).toString() + '%'
            // 当100%关闭定时器
            if (progress == 100) {
                convertComplete = true
                progressBar.style.width = "100%"
                progressPercent.innerText = "100%"
                clearInterval(myInterval)
            }
        }).catch(error => {
            console.error('错误:', error);
            convertError.style.display = "inline"
            clearInterval(myInterval)
        })
posted @ 2025-04-03 15:20  一只大学生  阅读(15)  评论(0)    收藏  举报