我正在实现ajax进度条,但是即使没有调用ajax成功函数,xhr也会立即显示“正在上传100%”。
$.ajax({
data: //data,
type: 'post',
url: url,
async: false,
xhr: function() {
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
console.log(percentComplete);
$('#status').html('<b> Uploading -> ' + (Math.round(percentComplete * 100)) + '% </b>');
}
}, false);
return xhr;
},
},
success: // code
};