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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:28:02+00:00 2026-06-16T18:28:02+00:00

I have one api link that contains the top elements. From each element, I

  • 0

I have one api link that contains the top elements. From each element, I need to build the end of a second api call which will give me the rest of the elements I need and pull them out.

Let say the first json is (urlphonebrands) that contains 3 phone brands (Apple, Samsung & Nokia). The second json call depends on each brand name, like urlphonebrands/Nokia, or urlphonebrands/Samsung or urlphonebrands/Apple built automatically.

I need to loop through each brand name to get properties such as colors, battery life and size. But each color has another loop of choices, as for example, black, white, red. My end result will be,

Apple
    battery life: 
        6h
    color: 
        blue 
        black
Samsung: 
    battery life: 
        6h
    color:
        blue 
        black
Nokia:
    battery life: 
        3h
    color: 
        blue 

While I am able to loop through each top element successfully I can only retrieve the last color element of the first item, which indicates that I built the second loop incorrectly. Went a few hours through it and figured I could use some help. This is what I have,

$.getJSON("urlphonebrands", function(data){

    var brandBlock = data[0]['name'];

    $.each(data, function(index, brandBlock){

        var brand = brandBlock.name;

        $('#table').append('<tr><td>' + brand + '</td></tr>');

        //It works fine until this point

        $.getJSON("phonebrandsurl" + brand, function(data){

            $.each(brand, function (index2, brand){

                var color = data[0].name[0].color;

                $('#table').append('<tr><td>' + color + '</td></tr>');

            });


        });


    });

});

Which gives me something like,

Apple
    blue
    blue
Samsung
    blue
    blue
Nokia
    blue

This is the console.log output after the second api call,

[Object]
0: Object
brand: Array[17]
0: Object
battery life: "6h"
colors: Object
color: "blue"
  • 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-16T18:28:03+00:00Added an answer on June 16, 2026 at 6:28 pm

    try wrap second getJSON into anonymous function and pass brand as param::

    (function(brand){
      $.getJSON('phonebrandsurl' + brand, function(data){
      // ...
    }(brand))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a QR code image that's embedded from the Google Charts API. Recently
The setup: I have a standard .php file (index.php) that contains two includes, one
I have a submenu that contains 3 choices for the user. Each option when
I have a JS photo gallery that loads individual images from an API into
I have the result of one API (FourSquare) giving me this.. [[4e01728f814d9dac7d52b93d,Bark Boutique,40.7143528,-74.0059731],[4d9f92dfaffda35d5db2a748,Bark Boutique,40.7143528,-74.0059731]]
I am using Twitterizer API for accessing twitter related functionality. I have one demo
I have created tabs by using jQuery API and have bound one event handler
I am using Lotus Notes Java API for my application. I have send one
Here, the Sencha team explains how to have a one to many relationship: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store
I have written a WCF REST API for third-party use. One of the things

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.