"use strict"; var feeds = []; feeds as $feed) { ?> feeds.push(" 'feed', 'a' => 'actualize', 'params' => array ('id' => $feed->id (), 'ajax' => '1')), 'php'); ?>"); function initProgressBar(init) { if (init) { $("body").after("\
\ 0 / " + feeds.length + "
\ \
"); } else { window.location.reload(); } } function updateProgressBar(i) { $("#actualizeProgressBar").val(i); $("#actualizeProgress .progress").html(i + " / " + feeds.length); } function updateFeeds() { if (feeds.length === 0) { return; } initProgressBar(true); var i = 0; for (var f in feeds) { $.ajax({ type: 'POST', url: feeds[f], }).done(function (data) { i++; updateProgressBar(i); if (i === feeds.length) { initProgressBar(false); } }); } }