당신은 ajax
호출 xhr
이벤트를 사용하고, 그 다음에 progress event
를 연결하고, event.lengthComputable= true
경우, 당신은 가치를 얻을 것이다, 다른 사람이 값을받지 않습니다 확인할 수 있습니다. 다음 코드를 확인할 수 있습니다.
$.ajax({
type: 'POST',
dataType: 'json',
url: URL,
cache: false,
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
alert(thrownError);
},
xhr: function() {
var xhr = new window.XMLHttpRequest();
//Download progress
xhr.addEventListener("progress", function (evt) {
console.log(evt.lengthComputable);
if (evt.lengthComputable) {
var percentComplete = evt.loaded/evt.total;
console.log(percentComplete);
}
}, false);
return xhr;
},
beforeSend: function() {
// before send
},
complete: function() {
// complete.
},
success: function (json) {
// success;
}
});
는 @StephenThomas가 지적했듯이,'HEAD' 요청을 시도해보세요'HEAD' 요청 –
검색'lengthComputable' – Anthony
를 사용; 'Content-Length' 헤더에 대한 응답을 구문 분석합니까? – guest271314