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

  • SEARCH
  • Home
  • 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 6720929
In Process

The Archive Base Latest Questions

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

Using setInterval to reload a script – it does not reload before the first

  • 0

Using setInterval to reload a script – it does not reload before the first amount of time has passed (i.e: waits 120000 msec before actually displaying content). Is there a better way to do this?

 <script id="source" language="javascript" type="text/javascript">
setInterval( "reloading();", 120000  );  
  $(function () {
   reloading = function(){
      $.ajax({                                      
      url: 'api.php',                  
      data: "",                      
      dataType: 'json',               
      success: function(data)         
      {
        var id = data[0];             
          _id = id;
        var vname = data[1];           
        var message = data[2]; 
        var timestamp = data[3]; 
        var field1 = data[4]; 
        _field1 = field1;
        var val2 = parseInt(field1, 10) + 1;
        _val2 = val2;
        $('#output').hide().html(timestamp +message ).fadeIn("slow");   
         $('#username').hide().html( vname ).fadeIn("slow");
              } 
    });
}}); 
  </script>
  • 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-26T09:16:13+00:00Added an answer on May 26, 2026 at 9:16 am

    1 you are declaring reloading as a global variable and accessing it without knowing if your function is ready, that’s not a good idea. If by any chance your site takes more than 2 minutes to load that will never work.

    If you want to queue up your re-loads to process once every 2 minutes and run the first time without waiting, you can do it like this:

    $(function(){
      function reloading(){
        //whatever you want to process goes here
        (...)
    
        setTimeout(function(){
          reloading();
        }, 120000);
    
      }
    
      reloading();
    });
    

    this will load your code once and then wait 12 seconds to run it again, and so on…

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

Sidebar

Related Questions

Im using SetInterval(); function to display time ,and sometimes it stop's it's not a
i'm using setInterval to check if a p(html paragraph) has a certain text value.
Is the jQuery live method using setInterval to update the events? Does this affect
I am using setInterval(fname, 10000); to call a function every 10 seconds in JavaScript.
Please advise how to pass parameters into a function called using setInterval . My
I'm using the simple jQuery DIV refresh code. var refreshId = setInterval(function() { $('#refreshdash').load('dashboard.php?cache=');
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I have a news feed that has been developed using PHP, MySQL, and jQuery.
Thanks to Refresh (reload) a page once using jQuery? answer I could solve an
I have a simple slideshow which automatticlly changes the image using setInterval every 5

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.