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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:38:03+00:00 2026-06-12T12:38:03+00:00

Im having some trouble displaying some JSON objects. If the object is displayed using

  • 0

Im having some trouble displaying some JSON objects. If the object is displayed using $.each() then it will display on screen twice. If I dont use $.each() to display the object then it displays once. The example shows below that the ruler content will be loaded twice, but the text content will only be loaded in once.

The JSON file is only called once. I checked this up using Firebug.

Im using jQuery 1.8.0 and using the history.js plugin

The JSON file validates using jsonlint.com.

I need to find out why the elements are being displayed twice. Any help is appreciated.
Thanks

The code:

function JSONLoader(page)
{
    //The page is "about" page then..
    if(page == 'about')
    {

        $.getJSON('about.json', function(data, textStatus){
            var htmlRuler="";
            $.each(data.person, function(pageIndex, page){  

                //The ruler content will load in twice
                if(page.RulerDiv){
                    htmlRuler += '<ul>';
                    $.each(page.RulerDiv,function(rulerIndex, ruler){
                        htmlRuler += '<li><img class="'+ruler.imgClass+'" src="'+ruler.imgURI+'" alt="'+ruler.imgAlt+'" title="'+ruler.imgTitle+'"/></li>';                         
                    });
                    htmlRuler += '</ul>';
                }                       
                $('.RulerDiv').append(htmlRuler).fadeIn('slow');

                //This loads the text in once only.
                if(page.TextDiv){
                    var htmltext = '<p class="' + page.TextDiv.textClass+'">'+ page.TextDiv.Text + '</p>';      
                }
                $('.TextDiv').append(htmltext).fadeIn('slow');
            });
        });
    }
}

Some sample JSON for this. The array RulerDiv would be implemented twice.

{
"person": {
    "page": {
        "RulerDiv": [
                {
                    "imgURI": "../img/rulerButton.png",
                    "imgTitle": "",
                    "imgClass": "hover whoRulerDivImg",
                    "imgAlt" : ""
                },
                {
                    "imgURI": "../img/rulerButton2.png",
                    "imgTitle": "",
                    "imgClass": "hover RulerDivImg",
                    "imgAlt" : ""
                }
            ],
        "TextDiv": {
            "wText" : "He is alive",
            "textClass" : "fontClass"
        }
    }
}

}

  • 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-12T12:38:04+00:00Added an answer on June 12, 2026 at 12:38 pm

    FIXED

    The problem was that I was iterating over the data twice. Taking out the first .each() and changing the code to the code below fixes this bug.

    $.getJSON('about.json', function(data, textStatus){
                var htmlRuler="";  
    
                if(data.person.page.RulerDiv){
                    htmlRuler += '<ul>';
                    $.each(data.person.page.RulerDiv,function(rulerIndex, ruler){
                        htmlRuler += '<li><img class="'+ruler.imgClass+'" src="'+ruler.imgURI+'" alt="'+ruler.imgAlt+'" title="'+ruler.imgTitle+'"/></li>';                         
                    });
                    htmlRuler += '</ul>';
                }                       
                $('.RulerDiv').append(htmlRuler).fadeIn('slow');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble displaying SOME images on my android app. Just normal display image
I'm having some trouble with displaying results from a datasource. This code will show
I am having some trouble displaying a div on click using JQuery. All the
My Java application is displaying some odd behaviour, and I'm having trouble finding a
Having some trouble with R's garbage collection, when passing objects to C++. We have
Basically having some trouble with using Hover to hide or show an item. The
I am having some trouble displaying XML values stored in my arrays. I successfully
I'm having some trouble displaying the time in this format: HH:mm:ss. No matter what
I'm having some trouble with displaying a popup div with CSS. The problem is
I'm writing a news-app and I'm having some trouble with displaying a custom list.

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.