Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using jQuery will make this simpler.</p> <p>The following will take an array of arrays and store convert them into rows and cells.</p> <pre><code>$.getJSON(url , function(data) { var tbl_body = ""; var odd_even = false; $.each(data, function() { var tbl_row = ""; $.each(this, function(k , v) { tbl_row += "&lt;td&gt;"+v+"&lt;/td&gt;"; }) tbl_body += "&lt;tr class=\""+( odd_even ? "odd" : "even")+"\"&gt;"+tbl_row+"&lt;/tr&gt;"; odd_even = !odd_even; }) $("#target_table_id tbody").html(tbl_body); }); </code></pre> <p>You could add a check for the keys you want to exclude by adding something like</p> <pre><code>var expected_keys = { key_1 : true, key_2 : true, key_3 : false, key_4 : true }; </code></pre> <p>at the start of the getJSON cbf and adding</p> <pre><code>if ( ( k in expected_keys ) &amp;&amp; expected_keys[k] ) { ... } </code></pre> <p>around the tbl_row += line.</p> <p>Edit: Was assigning a null variable previously</p> <p>Edit: Version based on <a href="https://stackoverflow.com/users/265521/timmmm">Timmmm</a>'s <a href="https://stackoverflow.com/a/27821863/1272141">injection-free</a> contribution.</p> <pre><code>$.getJSON(url , function(data) { var tbl_body = document.createElement("tbody"); var odd_even = false; $.each(data, function() { var tbl_row = tbl_body.insertRow(); tbl_row.className = odd_even ? "odd" : "even"; $.each(this, function(k , v) { var cell = tbl_row.insertCell(); cell.appendChild(document.createTextNode(v.toString())); }) odd_even = !odd_even; }) $("#target_table_id").appendChild(tbl_body); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload