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

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

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 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!