Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my Ajax code building an empty <tr> as first item?
    primarykey
    data
    text
    <p>Im receiving the following JSON object:</p> <pre><code>[Object, Object, Object] 0: Object a: "a" b: "b" c: "c" __proto__: Object 1: Object a: "a" b: "b" c: "c" __proto__: Object 2: Object a: "a" b: "b" c: "c" __proto__: Object length: 3 __proto__: Array[0] </code></pre> <p>With the following ajax code:</p> <pre><code>function describeItems() { var html; var loadingContainer = $("&lt;div class='containerLoading'&gt;&lt;/div&gt;"); var emptyContainer = $('&lt;div class="emptyContainer"&gt;&lt;div style="width: 400px; margin-left:20px;"&gt;&lt;h4&gt;Let\'s get started!&lt;/h4&gt;You do not have anything in your bucket.&lt;br \&gt;Click the shop button to start shopping items.&lt;button style="margin-top: 20px;" class="btn btn-large btn-primary" type="button" data-toggle="modal" data-target="#shop-items"&gt;Shop Items&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;'); $("#items-table").append(loadingContainer.fadeIn(100)); $.ajax( { type: "POST", url: "function.php", data: {action: 'test'}, dataType: "json", cache: "false", success: function(data) { // DEBUG console.log(data) if (data != null) { // DEBUG //console.log(data); html = html + '&lt;tr&gt;'; html = html + '&lt;td&gt;&lt;input type="checkbox" value=""&gt;&lt;/td&gt;'; $.each(data, function(key,value) { if (!$.isPlainObject(value)) { html = html + '&lt;td&gt;' + value + '&lt;/td&gt;'; }; }); html = html + '&lt;/tr&gt;'; $.each(data, function(key,value) { html = html + '&lt;tr&gt;'; html = html + '&lt;td&gt;&lt;input type="checkbox" value=""&gt;&lt;/td&gt;'; if ($.isPlainObject(value)) { // DEBUG //console.log(value); $.each(data[key], function(key, value) { html = html + '&lt;td&gt;' + value + '&lt;/td&gt;'; }); }; html = html + '&lt;/tr&gt;'; }); html = html + '&lt;/tbody&gt;'; // ADD THE HTML TO THE DIV. $('#innerContent').html(html); // WHEN LOADING IS DONE, REMOVE OVERLAY. $("#item-table .containerLoading").fadeOut(100, function() { $(this).remove(); }); } else { // WHEN LOADING IS DONE, REMOVE OVERLAY. $("#item-table .containerLoading").fadeOut(100, function() { $(this).remove(); }); $("#item-table").append(emptyContainer.fadeIn(100)); } }, // END OF SUCCESS error: function (xhr, ajaxOptions, thrownError) { alert('Response Code: ' + xhr.status); alert(thrownError); alert(xhr.responseText); } }); // END OF $.AJAX }; </code></pre> <p>But somehow my html table has an empty <code>&lt;tr&gt;</code> in it, at least it has not object content in it..:</p> <pre><code>&lt;table class="table table-striped table-condensed"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;a&lt;/th&gt; &lt;th&gt;b&lt;/th&gt; &lt;th&gt;c&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody id="innerContent"&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" value=""&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" value=""&gt; &lt;/td&gt; &lt;td&gt; a &lt;/td&gt; &lt;td&gt; b &lt;/td&gt; &lt;td&gt; c &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" value=""&gt; &lt;/td&gt; &lt;td&gt; a &lt;/td&gt; &lt;td&gt; b &lt;/td&gt; &lt;td&gt; c &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" value=""&gt; &lt;/td&gt; &lt;td&gt; a &lt;/td&gt; &lt;td&gt; b &lt;/td&gt; &lt;td&gt; c &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>What do I need to change to remove the first empty <code>&lt;tr&gt;</code>?</p>
    singulars
    1. This table or related slice is empty.
    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. 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