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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:29:47+00:00 2026-06-18T19:29:47+00:00

i have searched from stackoverflow and implemented the following jquery code, which is to

  • 0

i have searched from stackoverflow and implemented the following jquery code, which is to get the json object from php and append it as li tags, but its appending 3 instances of one value.
Sample code is:

   var $childs = $('.childs');


            $.getJSON('common/db/fetchUniversity.php', function(data) {
            $(data).each(function() {
                var $element = $childs.clone().removeClass('childs').appendTo('#colleges');
                $element.attr('id', this.id+"u");
                $element.html("<a href='#' class='img'><strong><img alt='image' src='images/mit.jpg' style='height:40px; width:40px;' /></strong></a><div style='padding-right: 30px;'><h4 style='display:inline; margin:1px;'>"+this.name+"</h4><p style='display:inline;'>"+this.description+"</p></div><p style='margin:2px;'><a href='#' style='text-decoration: none;'><span class='ui-icon ui-icon-circle-plus' style='display:inline-block; vertical-align:middle;'></span>Follow</a></p><ul class='actions'><li class='remove'><a href='javascript:RemoveMe('#"+this.id+"u')'><span class='ui-icon ui-icon-closethick'>close</span></a></li></ul>");
                });
            });


            $.getJSON('common/db/fetchPeople.php', function(data1) {
                $(data1).each(function() {
                    var $element = $childs.clone().removeClass('childs').appendTo('#people');
                    $element.attr('id', this.id+"p");
                    $element.html("<a href='#' class='img'><strong><img alt='image' src='"+btoa(this.pic)+"' style='height:40px; width:40px;' /></strong></a><div style='padding-right: 30px;'><h4 style='display:inline; margin:1px;'>"+this.name+"</h4><p style='display:inline;'>"+this.job_desc+","+this.location+"</p></div><p style='margin:2px;'><a href='#' style='text-decoration: none;'><span class='ui-icon ui-icon-circle-plus' style='display:inline-block; vertical-align:middle;'></span>Follow</a></p><ul class='actions'><li class='remove'><a href='javascript:RemoveMe('#"+this.id+"p')'><span class='ui-icon ui-icon-closethick'>close</span></a></li></ul>");
                    });
                });


            $.getJSON('common/db/fetchGroups.php', function(data) {
                $(data2).each(function() {
                    var $element = $childs.clone().removeClass('childs').appendTo('#groups');
                    $element.attr('id', this.id+"g");
                    $element.html("<a href='#' class='img'><strong><img alt='image' src='images/groups/hbr.jpg' style='height:40px; width:40px;' /></strong></a><div style='padding-right: 30px;'><h4 style='display:inline; margin:1px;'>"+this.name+"</h4><p style='display:inline;'>"+this.job_desc+","+this.location+"</p></div><p style='margin:2px;'><a href='#' style='text-decoration: none;'><span class='ui-icon ui-icon-circle-plus' style='display:inline-block; vertical-align:middle;'></span>Follow</a></p><ul class='actions'><li class='remove'><a href='javascript:RemoveMe('#"+this.id+"g')'><span class='ui-icon ui-icon-closethick'>close</span></a></li></ul>");
                    });
                });

the above code is fetching 3 json objects, and appending it to li tags, but all the above are adding 3 instances of single value. li tags are inside of jquery accordion.

When i hit json php file, its returning correct, i guess jquery code is doing something wrong to me. Please let me know where i am going wrong.

json object, when entered in browser:-

[{"id":1,"name":"Stanford university","description":"One of the best university in the world"},{"id":2,"name":"Princeton University","description":"One of the best university in the world"},{"id":3,"name":"Yale University","description":"One of the best university in the world"},{"id":4,"name":"California University","description":"One of the best university in the world"},{"id":5,"name":"Yale University","description":"One of the best university in the world"},{"id":6,"name":"California University","description":"One of the best university in the world"},{"id":7,"name":"Princeton University","description":"One of the best university in the world"},{"id":8,"name":"Stanford university","description":"One of the best university in the world"},{"id":9,"name":"California University","description":"One of the best university in the world"},{"id":10,"name":"Princeton University","description":"One of the best university in the world"},{"id":11,"name":"Yale University","description":"One of the best university in the world"}]

the above id:1 values are appending 3 times, it is happening for all the values.

  • 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-18T19:29:48+00:00Added an answer on June 18, 2026 at 7:29 pm

    Maybe there are more than one elements with class childs in your DOM.

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

Sidebar

Related Questions

I have written java code for generating json of my searched data from file.But
Looking for a php login script. I've searched stackoverflow and have seen a lot
I have searched up and down the internet for a jQuery widget that does
I have searched around but have been unsuccessful in determining whether the following approach
I have searched stackoverflow for a question like mine but most of the questions
I have searched through StackOverflow posts and various forums, but cannot find an answer.
I have googled a lot and also searched in stackoverflow.com about how to sort
I've searched and searched stackoverflow for the answer, but have not found what I
I have searched through the posts in stackoverflow and I hope this is not
I hope this is not a duplicate question. I have searched enough on Stackoverflow

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.