I have try to implement progress bar based on ajax response from server side (PHP).but i can't identify the progress bar calculation like how to calculate the progress bar timing between request and response of submit form through ajax.
<script>
$('.uploadProject').on('submit',function(e){
e.preventDefault();
//ray.ajax();
var formData = new FormData($(this)[0]);
progress(80, $('#progressBar'));
$.ajax({
url: "ajax/submitted_project_action.php",
type: "POST",
data: formData,
async: false,
success: function (data) {
if(data==1){
window.location.href="submitted_project.php?success";
}else{
window.location.href="submitted_project.php?error";
}
},
cache: false,
contentType: false,
processData: false
});
})
<script>
function progress(percent, $element) {
var progressBarWidth = percent * $element.width() / 100;
$element.find('div').animate({ width: progressBarWidth },500).html(percent + "% ");
}
</script>
My HTML COde
<style>
#progressBar {
width: 400px;
height: 22px;
border: 1px solid #111;
background-color: #292929;
}
#progressBar div {
height: 100%;
color: #fff;
text-align: right;
line-height: 22px; /* same as #progressBar height if we want text middle aligned */
width: 0;
background-color: #0099ff;
}
</style>
<div id="progressBar"><div></div></div>