Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with inserting a string containing html table rows (fetched by jquery ajax) into an html table - strange element jumble?
    primarykey
    data
    text
    <p>I'm trying to load a web page content little by little as the user scrolls since the content is huge, and the user is usually only interested in the first part(s) of it. </p> <p>The page consists of a big table. Everytime the user scrolls to the bottom of the page, I get a few more rows using ajax and append it to the table. Or, I want it to work that way...</p> <p>My scrollingevent works as it should. The ajax request is sent as it's supposed to, and I get the data as intended. The problem starts when I want to append this data to the table.</p> <p>Let's say my answer to the ajax request (called 'data' in my script) is a string like this:</p> <pre><code>'&lt;tr class="tasklist" id="r11"&gt; &lt;td class="titlecell"&gt;Some kind of string title&lt;/td&gt; &lt;td&gt;Some kind of string&lt;/td&gt; &lt;/tr&gt; &lt;tr class="tasklist" id="r12"&gt; &lt;td class="titlecell"&gt;Some other kind of string title&lt;/td&gt; &lt;td&gt;Some other kind of string&lt;/td&gt; &lt;/tr&gt;' </code></pre> <p>Then I try to use .after(data) to append those rows to my table. Only on web page, those rows fore some strange reason are inserted in the table like this:</p> <pre><code>'&lt;tr&gt; &lt;td class="titlecell"&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="tasklist" id="r11"&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td class="titlecell"&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="tasklist" id="r12"&gt;&lt;/tr&gt;' </code></pre> <p>No cell content at all, and cells are inserted in extra rows, leaving the "original" rows empty. Not really what I wanted right? But why? Any of you web oracles who can put me back on my track again by explaining what I'm doing wrong or what a better (working) solution should look like, I'd be really really grateful!</p> <p>This is my javascript function as it looks right now:</p> <pre><code>SPECIAL.loadMyTaskList = function() { // to avoid multiple simultaneous function calls if ($('div #loader').html().trim() == '') { var last = $("#mytasklist .tasklist:last").attr("id"); last = last.substring(1); // row id is on format r[number] $('div #loader').html('&lt;img src="images/loading.gif" alt="Wait..."&gt; Loading more tasks'); $.get('includes/mytasklist.php?from='+last+'&amp;nbr=10&amp;ajax=1', function(data) { if (data=='') // all data is already loaded $(window).unbind('scroll'); else // append to table #mytasklist, after // the last row (with class tasklist) $("#mytasklist .tasklist:last").after(data); // if browser window is so large, that the first // post(s) of data fits without creating a scrollbar if (!BASIC.pageHasScrollbar()) SPECIAL.loadMyTaskList(); $('div #loader').empty(); }); } } </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.
 

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