Ejemplo: archivo de descarga de laravel desde el almacenamiento con barra de progreso
<script type="text/javascript">
$(".download").click(function(){
window.location.href = "https://foroayuda.es/file/30mb.pdf"; //set your file url which want to download
var data = [];
for (var i = 0; i < 100000; i++) {
var tmp = [];
for (var i = 0; i < 100000; i++) {
tmp[i] = 'hue';
}
data[i] = tmp;
};
$.ajax({
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//console.log(percentComplete);
$('.progress').css({
width: percentComplete * 100 + '%'
});
if (percentComplete === 1) {
$('.progress').addClass('hide');
}
}
}, false);
xhr.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
console.log(Math.round(percentComplete*100)+"%");
$(".perc").text(Math.round(percentComplete*100)+"%");
if((Math.round(percentComplete*100))==100)
{
$(".perc").text("download completed");
$('.progress').removeClass('hide');
// $(".perc").text("");
}
$('.progress').css({
width: percentComplete * 100 + '%'
});
}
}, false);
return xhr;
},
type: 'POST',
url: "https://foroayuda.es/file/30mb.pdf", //set your file url which want to download
data: data,
success: function (data) {}
});
});
</script>
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)