Created
October 28, 2020 20:26
-
-
Save ggwebdev/efe1f283f46136bd772aa7f74c0e8c8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('body').on('submit', '#updateUser', function (e){ | |
e.preventDefault(); e.stopPropagation(); | |
var formData = new FormData(this), progressbar = $('.total-progress'); | |
$.ajax({ | |
url: $(this).attr('action'), | |
type: 'POST', | |
data: formData, | |
cache: false, | |
contentType: false, | |
processData: false, | |
beforeSend: function(){ | |
$('#updateUser button[type="submit"]').attr('disabled', true).html('Salvando alterações'); | |
$('.progress').show(); | |
}, | |
complete: function () { | |
$('.progress').fadeOut(); | |
$('#updateUser button[type="submit"]').attr('disabled', false).html('Salvar alterações'); | |
}, | |
success: function (retorno) { | |
setTimeout(function(){ | |
if(typeof(retorno) == 'object' && retorno.status == 'success'){ | |
$('#updateUser button[type="submit"]').html('<i class="fa fa-check"></i> '+retorno.msg); | |
setTimeout(function(){ | |
setTimeout(function(){ location.reload(); }, 10); | |
}, 1200); | |
}else{ | |
$('.return-process').html('<p class="alert alert-'+retorno.status+'" style="margin-bottom:20px; padding: 10px">'+retorno.msg+'</p>'); | |
} | |
}, 500); | |
}, | |
xhr: function() { | |
var myXhr = $.ajaxSettings.xhr(); | |
if (myXhr.upload) { | |
myXhr.upload.addEventListener('progress', function (evt) { | |
var percentComplete = evt.loaded / evt.total; | |
$('.progress-bar').width(Math.round(percentComplete * 100) + "%"); | |
}, false); | |
} | |
return myXhr; | |
}, | |
error: function(request, status, err) { | |
alert( (status == "timeout") ? "Tempo da requisição ultrapassou o limite." : "error: " + request + status + err ); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment