Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Load the data into html table from json formatted variable

I need to load json dump data returning from a python script into my html table, not sure what am i doing wrong as i am relative new to html and doing this for a POC. I'm unable to load the data into a html table. seeking your help.

Python Code
def read_data_from_sql(sqlserverinst,uname,psswd,dbname,url,regime,jurisdiction):
    output=[]
    conn = pymssql.connect(sqlserverinst, uname, psswd, dbname)
    cursor = conn.cursor(as_dict=True)
    cursor.execute('SELECT * FROM [reg_content_extracted_url_browsed]')
    for row in cursor:
    output.append({'url_id': row['url_id'],'url': row['url'],'regime': row['regime'],'jurisdiction': row['jurisdiction']})
    # flat_list = [item for sublist in output for item in sublist]
    conn.close()
    print(json.dumps(output))
    return json.dumps(output)

Output format : [{"url_id": 1, "url": "www.google.com", "regime": "FATCA", "jurisdiction": "SG"}]

HTML Table layout
<div class="content-large">Successful Browsed URL(s)
    
    <!-- <style>
        table, th, td {
        border:1px solid black;
        }
    </style> -->
    <table id="btable" style="width:100%">
        <tr style="color: white;">
          <th>url id ID</th>
          <th>url</th>
          <th>Regime</th>
          <th>Jurisdiction</th>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          
        </tr>            
    </table>
</div>

Script to populate json data
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> 
</script>
<script type=text/javascript>
$(function() {
  $('a#test').on('click', function(e) {
    e.preventDefault()
    $.get('/datahomepage',
        function(data) {
            // alert(data);
            alert(data.length)
            // console.console.log("hheh"); 
            var tr;
            for (var i=0;i<data.length;i++){

                alert(data[i].url_id)
                tr = $('<tr/>');
                tr.append("<td>" + data[i].url_id+ "</td>");
                tr.append("<td>" + data[i].url+ "</td>");
                tr.append("<td>" + data[i].regime+ "</td>");
            $('btable').append(tr);
            }
            
    });
    // return false;
  });
});
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

An obvious error is:

$('btable').append(tr);

which should be

$('#btable').append(tr);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!