Answer the question
In order to leave comments, you need to log in
Why does the file always have a size of 34 bytes when indicating the progress of a file download?
Hello! I wrote this script. For some reason, this is always displayed in the console, regardless of the selected file:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Запрос к серверу</title>
</head>
<body>
<!-- Тип кодирования данных, enctype, ДОЛЖЕН БЫТЬ указан ИМЕННО так -->
<form name="upload">
<input type="file" name="file"><br>
<input type="submit" value="Отправить файл на сервер">
</form>
</body>a
</html>
<script>
document.forms.upload.onsubmit = function(){
//var formData = new FormData();
// formData.append("name", "Евгений");
var xhr = new XMLHttpRequest();
xhr.onprogress = function(e){
console.log("Загружено - " + e.loaded + "\n Из - " + e.total);
}
xhr.onload = function(){
console.log(this.responseText);
}
xhr.open("POST", "http://asd/php.php", true);
xhr.send(this.elements.file.files[0]);
//console.log(this.elements.file);
return false;
}
</script>
Answer the question
In order to leave comments, you need to log in
That's right -
xhr.upload.onprogress = function(event) {
console.log(event.loaded + ' / ' + event.total);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question