Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6348529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:26:16+00:00 2026-05-24T21:26:16+00:00

I am trying to load 2 different PHP files after certain interval by users

  • 0

I am trying to load 2 different PHP files after certain interval by users click.
Here’s the code snippet, help me through this:

function load_recent_popular(recent) {
    if( typeof load_recent_popular.counter == 'undefined' ) { 
        load_recent_popular.counter = 0;  
    }
    if(recent==1) {
        var loadUrl = "1.php"; 
        $("#box15").load(loadUrl); 
        load_recent_popular.counter = 0;  
    }
    else {
        var loadUrl = "2.php"; 
        $("#box15").load(loadUrl); 
        load_recent_popular.counter = 1;  
    }
    handle = setInterval(function() { 
        if(load_recent_popular.counter == 0) { 
            loadUrl = "1.php";  
        }
        else if(load_recent_popular.counter == 1) { 
            loadUrl = "2.php";  
        }
        $("#box15").load(loadUrl); 
    }, 10000);  
}

<a onClick="load_recent_popular(1)">Load 1</a><a onClick="load_recent_popular(2)">      Load 2</a>

<div id="box15"></div>

I tried to include 2 different intervals with 2 different handles for each and inserted module to clear 1 interval before starting another, but it is not working so if anyone got solution for that too, please share.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:26:17+00:00Added an answer on May 24, 2026 at 9:26 pm

    You’ll end up with multiple timers running but it looks okay other than. For the timer problem, you could store the timer ID using .data on the #box15 and then call clearTimeout to stop it before starting a new one. Something like this:

    function load_recent_popular(recent) {
        var $box15 = $('#box15');
        var timer  = $box15.data('lrp_timer');
        if(timer)
            clearInterval(timer);
    
        if( typeof load_recent_popular.counter == 'undefined' ) { 
            load_recent_popular.counter = 0;  
        }
        if(recent==1) {
            var loadUrl = "1.php"; 
            $("#box15").load(loadUrl); 
            load_recent_popular.counter = 0;  
        }
        else {
            var loadUrl = "2.php"; 
            $("#box15").load(loadUrl); 
            load_recent_popular.counter = 1;  
        }
        $box15.data('lrp_timer', setInterval(function() { 
            if(load_recent_popular.counter == 0) { 
                loadUrl = "1.php";  
            }
            else if(load_recent_popular.counter == 1) { 
                loadUrl = "2.php";  
            }
            $("#box15").load(loadUrl); 
        }, 10000));
    }
    

    And a live demo of the technique (shorter time interval, no AJAX): http://jsfiddle.net/ambiguous/MagL4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement this code to have different files to load for german,
Currently I'm trying to read different install.rdf files of Firefox extensions via PHP's SimpleXML.
I am trying to load/show completely different set of values in a combobox(this one
I am trying to load UIImage object from NSData , and the sample code
I have a live site that includes different php files depending on what page
I've been trying a bunch of different directory structures for my PHP MVC framework.
I'm trying to execute a straightforward PHP call to load the contents of a
I use this code to load the content from a different page into the
I am trying to import various pipe delimited files using php 5.2 into a
I am trying to load an extension of a php class by itself. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.