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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:38:43+00:00 2026-05-20T04:38:43+00:00

I am trying to use javascript and jquery to build an HTML table based

  • 0

I am trying to use javascript and jquery to build an HTML table based on information returned from a database. I have the JSON and the database hit working properly, but I am unable to show the data on my page.

This is code to display the data

var temp;

var init = function() {
    $(_getMarketInfo()).appendTo(document.body);

    // Used for logging
    temp = $(_getMarketInfo());
    console.log(temp);
};

And then to get and process the data

function _getMarketInfo() {
    $.ajax({
        url:'scripts/db_getMarketInfo.cgi',
        dataType:'json',
        success:function(data, testStatus) {
            var html = '';
            html +='<div class="marketInfoHolder">';
            html +='<table class="tbl" border=1>';
            html +='    <tr><th>Market Information</th></tr>';
            html +='    <tr><td>Market</td></tr>';

            for (var i=0;i< data.marketInfo.length; i++){
                html += '<tr><td>' + data.marketInfo[i].market_name + '</td></tr>';
            }

            html +='</table>';
            html +='</div>';

            //used for logging
            console.log(html);

            return html;
        },
        error:function(data, textStatus) {
            alert('There was an error getting market information.');
        }
    });
 };

According to the console logs, the html variable does have proper html code for a table, but then when I look at temp variable, it is logged as []. It appears that, for some reason, the _getMarketInfo() isn’t properly returning html to temp.

  • 1 1 Answer
  • 2 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-20T04:38:44+00:00Added an answer on May 20, 2026 at 4:38 am

    I would use a custom event that is triggered on the success of the ajax call.

    var init;
    
    // bind a custom event to the document that is
    // triggered in your ajax success callback
    $(document).bind('init', function (html) {
        init = html;
    
        // Used for logging
        console.log(init);    
    });
    
    // run _getMarketInfo in a document ready handler
    // because you are accessing the DOM
    $(document).ready(function () {
        $(_getMarketInfo()).appendTo(document.body);    
    });
    
    // your ajax call function
    function _getMarketInfo() {
        $.ajax({
            url:'scripts/db_getMarketInfo.cgi',
            dataType:'json',
            success:function(data, testStatus) {
                var html = '';
                html +='<div class="marketInfoHolder">';
                html +='<table class="tbl" border=1>';
                html +='    <tr><th>Market Information</th></tr>';
                html +='    <tr><td>Market</td></tr>';
    
                for (var i=0;i< data.marketInfo.length; i++){
                    html += '<tr><td>' + data.marketInfo[i].market_name + '</td></tr>';
                }
    
                html +='</table>';
                html +='</div>';
    
                // trigger your custom event with
                // the html used as a custom parameter;
                // custom event parameters must be passed
                // in an array
                $(document).trigger('init', [html]);
    
                // return your html for appending
                return html;
            },
            error:function(data, textStatus) {
                alert('There was an error getting market information.');
            }
        });
     };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to dynamically build a table in javascript and I already have
I am trying to use Javascript/jQuery to resize part of a website based on
I'm trying to use Javascript to access data from http://www.bart.gov/dev/eta/bart_eta.xml , however, I found
im trying to use html and javascript to create a rotating logo on my
I am trying to build a progress bar using jQuery and javascript. It is
In an attempt to follow best practices, we're trying to use the proper JavaScript/jQuery
I'm trying to use JQuery's $.getJSON to access Model data from the Controller, and
Fairly new to jQuery, trying to use Autocomplete. Went to http://jqueryui.com/download to build my
Im using Coda, and Im trying to write a program to use Javascript/Jquery to
I trying to build a JavaScript function which will grab a JSON encoded array

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.