Note that there are some explanatory texts on larger screens.

plurals
  1. POMost efficient way to populate a page through specified time intervals?
    primarykey
    data
    text
    <p>I'll get straight to it.</p> <p>layout.html</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;div id="corner1"&gt;&lt;/div&gt;&lt;div id="c11"&gt;&lt;/div&gt;&lt;div id="c12"&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="corner2"&gt;&lt;/div&gt;&lt;div id="c21"&gt;&lt;/div&gt;&lt;div id="c22"&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;div id="corner3"&gt;&lt;/div&gt;&lt;div id="c31"&gt;&lt;/div&gt;&lt;div id="c32"&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="corner4"&gt;&lt;/div&gt;&lt;div id="c41"&gt;&lt;/div&gt;&lt;div id="c42"&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="hidden" value="12" name="tableid" /&gt; </code></pre> <p>main.js</p> <pre><code>populateID = setInterval(Populate, 1000); function Populate() { $.ajax({ url: 'jquery/populate.php', data: 'tableid=' + $("#tableid").val(), success: function(data) { fillem(data); } }); } function fillem(data) { if(data.c1) { $("#c11").html(data.c1); $("#c12").html(data.filler); }else{ $("#c11").html(data.filler); } if(data.c2) { $("#c21").html(data.c2); $("#c22").html(data.filler); }else{ $("#c21").html(data.filler); } if(data.c3) { $("#c31").html(data.c3); $("#c32").html(data.filler); }else{ $("#c31").html(data.filler); } if(data.c4) { $("#c41").html(data.c4); $("#c42").html(data.filler); }else{ $("#c41").html(data.filler); } if(data.timer) { $("#timer").html(data.timer); }else{ $("#timer").html(""); } if(data.corner) { $("#corner" + data.corner).html("ACTIVE"); } } </code></pre> <p>I'm pretty sure this could be done in a more efficient way, I don't care if it involves changing the DOM structure.</p> <p>For example, It does sound bad to always have 4 "corner" divs when no two of them will be used simultaneously. And since the ajax response will change upon every request, sometimes a div "flashes" quickly when being populated with new data, which is also annoying.</p> <p>Thanks for reading.</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.
 

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