Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Run AJAX every x seconds with different data each time

I have the below code whichs executes every 5 seconds. However i would like to return different data each time.

For example:

First interval = top level data (level.php)
Second interval = top skill data (skill.php)
Third interval = top magic data (magic.php)

And once the third interval is done... return to level.php to start the sequence again

Can someone tell me how would i modify the code to achieve what i want?

<script>
    var text = "";
    var toplevel = function() {
        $.ajax({
            type : 'GET',
            url : '/pages/level.php',
            success : function(data){
            text = data;
            $("#tops").fadeOut( "normal", function() {
                $('#tops').html(data);
                $("#tops").fadeIn( "normal", function() {});
                });
            },
        });
    };

    $(document).ready(function(){
        setInterval(toplevel, 5000);
        toplevel();
    });
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could have an array of URLs, always send the request to the first one, and rotate the array order on success:

function toplevel(urls) {
    return function () {
        $.get(urls[0]).done(function (data) {
            urls.push(urls.shift());
            $("#tops").fadeOut("normal", function () {
                $('#tops').html(data).fadeIn( "normal");
            });
        });
    }
};

$(function () {
    var switcher = toplevel(['/pages/level.php', '/pages/skill.php', '/pages/magic.php']);
    setInterval(switcher, 5000);
    switcher();
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda