Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Ejecute AJAX cada x segundos con datos diferentes cada vez

Tengo el siguiente código que se ejecuta cada 5 segundos. Sin embargo, me gustaría devolver datos diferentes cada vez.

Por ejemplo:

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

Y una vez que termine el tercer intervalo... regrese a level.php para comenzar la secuencia nuevamente

¿Alguien puede decirme cómo modificaría el código para lograr lo que quiero?

 <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 answers
Answer question

0

Podría tener una matriz de URL, enviar siempre la solicitud a la primera y rotar el orden de la matriz en caso de éxito:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!