gpt4 book ai didi

jquery - 有没有办法获取jQuery ajax上传进度?

转载 作者:行者123 更新时间:2023-12-03 22:30:30 24 4
gpt4 key购买 nike

$.ajax({
xhr: function()
{
var xhr = new window.XMLHttpRequest();
//Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with upload progress
console.log(percentComplete);
}
}, false);
//Download progress
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with download progress
console.log(percentComplete);
}
}, false);
return xhr;
},
type: 'POST',
url: "/",
data: {},
success: function(data){
//Do something success-ish
}
});

这在 jQuery 1.5+ 上不起作用,因为 xhr 被 jqXHR 取代(即原始 XHR 的高级版本)。现在的问题是如何让它与 jqXHR 一起工作......有谁知道怎么做吗?

最佳答案

试试这个

$.ajax({
url: path,
xhr: function () {
var xhr = $.ajaxSettings.xhr();
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
console.log(e.loaded / e.total);
}
};
return xhr;
}
}).done(function (e) {

})

关于jquery - 有没有办法获取jQuery ajax上传进度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13203231/

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