由网友(陪伴是最长情的告白)分享简介:$.ajax({xhr: function(){var xhr = new window.XMLHttpRequest();//Upload progressxhr.upload.addEventListener("progress", function(evt){if (evt.lengthComputable) {...
$.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工作... 任何人都知道该怎么办呢?
This does not work on jQuery 1.5+ because the xhr is replaced by the jqXHR (i.e. a high level version of the raw XHR.) Now the question is how to get it to work with jqXHR… Anyone know how to do it?
推荐答案
试试这个
$.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) {
})
相关推荐
最新文章