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 8173735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:15:54+00:00 2026-06-06T22:15:54+00:00

I have a program that gets a JSON from the server using getJSON and

  • 0

I have a program that gets a JSON from the server using getJSON and processes this data and presents it to the user. But the data on the server is being updated every so often. How can I get the new JSON every 5 minutes and display it to the user and do it in a background thread? Can I use setTimeout for this?

Thanks!
Matt

  • 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-06-06T22:15:56+00:00Added an answer on June 6, 2026 at 10:15 pm

    Using an interval that fires every 5 minutes is the obvious (and most browser-compatible) approach.

    This does not create a separate thread, but is the traditional simulation of doing so. All that actually happens is the asynchronous event is queued up, to be executed at a time as close as possible to the point when you stipulated it should run. Precision is not guaranteed, though, because it’s running on the same thread, so it requires a ‘window of opportunity’ in the JS engine’s execution.

    In other words, the JS engine will do its best to execute your code at the required moment, but only insofar as it is free to do so.

    If you don’t mind about older browser support, you could use a web worker, which genuinely does run on a separate thread.

    web worker script

    self.addEventListener('message', function(evt) {
            var gateway = new XMLHttpRequest();
            var intie = setInterval(function() {
            gateway.open("GET",evt.data.load_url,true);
            gateway.send();
            gateway.onreadystatechange = function() {
                if (gateway.readyState==4 && gateway.status==200)
                    self.postMessage(gateway.responseText);
            }
       }, 300000); //every 5 minutes
    }, false);
    

    (Note I use vanilla JS there, not jQuery, as I’m not aware of any way of using jQuery inside web workers. You can import scripts, but jQuery references window, which errors in web workers as they do not have any ties to the window or DOM)

    Main JS script

    var worker = new Worker('worker.js');
    worker.addEventListener('message', function(evt) {
        //the loaded JSON data is now held in evt.data
        alert(evt.data);
    }, false);
    worker.postMessage({load_url: 'json.txt'});
    

    Whether there’s any benefit in calling a new worker every 5 minutes, or, as I have, using one worker and having it act every 5 minutes, I’m not sure. Probably not a lot in it since, in either case, there’s an interval going on.

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

Sidebar

Related Questions

I'm creating a program that gets data from a server using AJAX/JSON and then
I have made a program that gets some strings in input from the user
I have to write program that gets a number n from the user, and
I have a batch-file program that gets called from another batch-file so I can
I have a program in Python that gets a window handle via COM from
I need to write a program that gets three numbers from the user, then
hi i have a little program here that gets a directory from the command
I have an iOS app which gets some JSON from a server (in the
I have a program that gets a string from a method. I want to
I have a Windows C program that gets its data through a redirected stdin

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.