var images = []; var indexImages = 0; function afficherIndex() { $('#debug').text(indexImages); } function afficherImage() { $('#image').attr('src', "/api/contenu/"+images[indexImages]); } function augmenterIndex() { indexImages ++; } function executionLoop(){ if (indexImages >= images.length) { location.reload(); } afficherImage(); augmenterIndex(); } function obtenirContenu(){ var response = ''; $.ajax({ type: "GET", url: window.location.origin + "/api/contenu", async: false, success: function(text) { response = text; } }); console.log(response); images = response.split(';'); console.log(images); } $(function(){ obtenirContenu(); executionLoop(); var executionInterval = setInterval(executionLoop, (Math.floor(Math.random() * 6)+15)*1000); });