嗨我有ajax调用,需要40到50分钟才能得到响应,所以我试图使用xhr组件在ajax中显示进度条,但我直接输出100%而没有取得百分比进展。我使用控制台显示百分比。请检查我的代码并帮助解决它。
$('#test0').click(function(e){
$.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:'url',
data:{'type':'test0'},
dataType:'json',
success:function(data){
if(data.status == 'success'){
}else{
}
}
});
});