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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:04:45+00:00 2026-05-26T03:04:45+00:00

I am new to jQuery. I have to query 2 web services and based

  • 0

I am new to jQuery. I have to query 2 web services and based on an attribute value in first web service I have to query the next one and populate the result in a table using data from both web services.

Please have a look at the code at http://jsfiddle.net/ykPXZ/2/ . I am trying to append the table data to a div having id=”tableData”. I am getting the data from the web service and I have checked the console logs to see whether the data is getting appended to the variable tableDataA and it is getting appended but I am not to display the data on the web page. Somehow it is getting rewritten or deleted.

Please tell me if this is the best approach for solving this problem. Please suggest a better approach to it.

Thanks.

EDIT: Dynamically generated table is showing 23 rows instead of 24.

Hi, I am following the approach as mentioned by mu is too short in the first answer. The issue I am having now is that instead of getting all the 24 rows to be displayed in the table, it is displaying only 23 rows and missing the 1st row data. When I am logging it in the console, it shows all 24 entries but in the table 23 rows are getting displayed.

Please suggest some solution for the same.

Thanks.

EDIT: I have been able to solve the above issue of showing 23 rows instead of 24. It might be useful for others.In the correct answer below,instead of using the i, it should have been i+1.

     $tr = $('#tableData table tr:eq(' + i + ')');

replace it by

     $tr = $('#tableData table tr:eq(' + (i+1) + ')');

Thanks.

  • 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-05-26T03:04:46+00:00Added an answer on May 26, 2026 at 3:04 am

    The success callback from your main $.ajax call looks like this:

    success: function(data) {
        var tableDataA = '<table border="0" width="500">';
        $.each(data, function(i, detail) {
            $.getJSON("webService2", function(metaData) {
                // ...
            });
        });
    
        tableDataA = tableDataA + '</table>';
        $('#tableData').empty();
        $('#tableData').append(tableDataA);
    }
    

    Each of your $.getJSON calls is asynchronous so the callback functions that build tableDataA won’t be executed until some time after your success callback is finished. That means that when you get to the bottom of the success callback, you’re just doing this:

        $('#tableData').empty();
        $('#tableData').append('<table border="0" width="500"></table>');
    

    and you get an empty table. Later, when the $.getJSON calls finish, they will add some data to tableDataA but it will be too late, no one will care what’s in tableDataA at that point.

    You could replace your $.getJSON calls with synchronous $.ajax calls but your users will hate you for it.

    You could build the whole empty table in your success callback and then your $.getJSON callbacks would just fill in the blanks with something like this in your success callback:

    var tableDataA = '<table border="0" width="500">';
    for(var i = 0; i < data.length; ++i)
        tableDataA += '<tr><td></td><td></td><td></td><td></td></tr>';
    tableDataA += '</table>';
    $('#tableData').empty();
    $('#tableData').append(tableDataA);
    
    $.each(data, function(i, detail) {
        $.getJSON('webService2', function(metaData) {
            $tr = $('#tableData table tr:eq(' + i + ')');
            // Fill in the table cells in $tr
        });
    });
    

    If possible, it would be better to merge the two services into one that would give you the whole JSON blob that you need in one go. If you don’t have control over the remote systems then the above “fill in the blanks” approach might be the easiest approach.

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

Sidebar

Related Questions

I am new to jQuery and have been trying to query the PhishTank API
I am somewhat new to jQuery and I have a problem with something I
I have application that brings response via Ajax and creates 5-20 new jQuery click
I'm new to jQuery and I want to have a input box from a
I'm new to JQuery and was wondering how can I have Changes saved! displayed
I'm kind of new to JQuery and was wondering how can I have the
I am new to jQuery. Any help would be appreciated I have two radio
I'm new to jQuery so this may be a real simple answer. I have
Guys i am very new to jQuery. I have started using the auto complete
I am new to JQuery, so bear with me :). I have a simple

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.