Answer the question
In order to leave comments, you need to log in
How to make a progressbar to send email ajax + phpmailer?
Hello. I send a file using ajax and phpmailer from the site to my mail. It sends and arrives without problems, only there is a small problem: if you send a large file, the user will not be able to monitor what is happening and may think that nothing is happening, so I decided to fasten the progressbar.
There he is:
<progress id="progressbar" value="0" max="100"></progress>
$(function(){
'use strict';
var progressBar = $('#progressbar');
$('#form').on('submit', function(e){
e.preventDefault();
var fd = new FormData( this );
$.ajax({
url: 'send.php',
type: 'POST',
contentType: false,
processData: false,
data: fd,
success: function(msg){
if(msg == 'ok') {
$(".send").val("Отправлено");
} else {
$(".send").val("Ошибка");
setTimeout(function() {$(".send").val("Отправить");}, 3000);
}
},
xhr: function(){
var xhr = $.ajaxSettings.xhr();
xhr.upload.addEventListener('progress', function(evt){
if(evt.lengthComputable) {
var percentComplete = Math.ceil(evt.loaded / evt.total * 100);
progressBar.val(percentComplete).text('Загружено ' + percentComplete + '%');
}
}, false);
return xhr;
}
});
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question