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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:28:57+00:00 2026-06-08T04:28:57+00:00

I had a previous problem solved on stackoverflow but the requirments of my project

  • 0

I had a previous problem solved on stackoverflow but the requirments of my project have changed so I need a new solution. To summerise I have a getJSON function that executes every 5 seconds to read for change in a JSON file. The problem I am having is outputting the data correctly. I want the data to output once but update every 5 seconds in case the user makes changes to the JSON file

Here is my code

 <script type="text/javascript">
$.ajaxSetup({
    cache: false
});
setInterval(function() {
    $.getJSON('names.json', function(data) {
        for (var i in data) {
            $('#one').append(data[i]);
        }
    });
}, 5000);

</script>

This getJSON function allows me to grab JSON data and append it to the start of a div. Then I refreash the function so that if the JSON data changes then the data changes in the div. The problem is that the data repeats itself every 5 seconds.

The unexpected result after 15 seconds

453545Beady little eyesLittle birds pitch by my doorstep
453545Beady little eyesLittle birds pitch by my doorstep
453545Beady little eyesLittle birds pitch by my doorstep

The result I want after 15 seconds

453545Beady little eyesLittle birds pitch by my doorstep

If I change the JSON 11 seconds when the script is running

"two": "Eyes"

The result I want to get after 15 seconds

453545 Eyes Little birds pitch by my doorstep

Rather than the actual result I get after after 15 seconds

453545Beady little eyesLittle birds pitch by my doorstep
453545Beady little eyesLittle birds pitch by my doorstep
453545 Eyes Little birds pitch by my doorstep

Here is the JSON file I am using

{
  "one": "453545",
  "two": "Beady little eyes",
  "three": "Little birds pitch by my doorstep"
}

Hopefully I have made this as clear as possible

  • 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-08T04:28:58+00:00Added an answer on June 8, 2026 at 4:28 am

    It’s hard to decipher your question because there may be two different results of which one of them you’re actually trying to achieve:

    • have only the latest JSON result displayed (no change history)
    • have only one JSON result per change displayed (history of changes)

    The first one is simple and is as follows:

    no history: Clear results before displaying them

    Before you append your newly received results you have to clear previous ones.

    <script type="text/javascript">
    
        $.ajaxSetup ({  
            cache: false  
        });  
    
        setInterval(function(){
            $.getJSON('names.json', function(data) {
                $('#one').empty();
                for(var i in data) {
                    $('#one').append(data[i]);
                }
            });
        }, 5000);
    
    </script>
    

    change history: detect changes

    Keeping change history has several different approaches:

    1. First one has been somehow summarized by rogal111. Although his solution may not be best especially when the format of your resulting JSON changes, because his code only work when JSON results have at least those 4 fields defined. If any of them’s missing an undefined will get displayed and if any additional one is added it will be omitted.

    2. A more dynamic solution is provided by Trinh Hoang Nhu that works with any JSON object’s properties.

    3. The third possible solution would be to call your Ajax URL by appending timestamp of the last change (names.json/timestamp) and if server sees that JSON has changed afterwards, it would send the object otherwise some default object would be sent over (i.e. false or null) which would indicate that no change has been made…

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

Sidebar

Related Questions

The responses I've got to this question have solved the problem I had in
In my previous question I had a problem with sending parameters over the command
So I had an architect on a previous project who railed against Datasets. He
I currently had a problem similar to this previous question: Why would our Java
As I have said in my previous questions, I'm still new to Java. I'm
I had a math problem I solved like this: In[1]:= Solve[2x(a-x)==0, x] Out[1]= {{x->0},
I have some problem with my android project! I have created a preferences intent
From previous experience I had been under the impression that it's perfectly legal (though
In previous question of mine, someone had meantioned that using Semaphores were expensive in
I remember that in previous installations of Visual Studio that I had, when 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.