Note that there are some explanatory texts on larger screens.

plurals
  1. POSwitch between two JQuery Datatables
    text
    copied!<p>I have two JQuery datatables (datatables.net), one with messages and the second one with contacts. I would like to load them without refreshing the page, i.e. if I click link1 I get messages displayed, if I click link2 I get messages table disapear and contacts displayed. I can get it by placing tables in different divs and use .show and .hide on those. But what if I have 20 different tables I need to display with just one at a moment. It would be probably a lot of memory usage at the client side to load all 20 tables and hide those. I'm kind of stuck and overflowed).</p> <p>I have tried the following:</p> <pre><code>&lt;a href='#' onclick='test_widget();return false;' &lt;script type="text/javascript"&gt; function test_widget() { $.ajax({ type:'POST', url:'contacts.php', data:$('#test_widget').serialize(), success:function(data) { $('#test_widget').html(data); }, error:function(XMLHttpRequest, textStatus, errorThrown) { $("#test_widget").html(errorThrown + ': ' + this.url); }, dataType:'html' }); } &lt;/script&gt; &lt;div id='test_widget'&gt;&lt;/div&gt; </code></pre> <p>And then the contacts.php:</p> <pre><code>&lt;table class="table table-bordered table-striped checked-in has-checkbox" id="dtable"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Last Name&lt;/th&gt; &lt;th&gt;First Name&lt;/th&gt; &lt;th&gt;Middle Name&lt;/th&gt; &lt;th&gt;Email&lt;/th&gt; &lt;th&gt;Phone&lt;/th&gt; &lt;th&gt; &lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;? $res=mysql_query('SELECT * FROM people ORDER BY lname LIMIT 1000'); while($row=mysql_fetch_array($res)){ ?&gt; &lt;tr class="gradeA"&gt; &lt;td&gt;&lt;?=$row['lname']?&gt; &lt;/td&gt; &lt;td&gt;&lt;?=$row['fname']?&gt; &lt;/td&gt; &lt;td&gt;&lt;?=$row['patronymic']?&gt; &lt;/td&gt; &lt;td class="center"&gt;&lt;?=$row['email']?&gt; &lt;/td&gt; &lt;td class="center"&gt;&lt;?=$row['phones']?&gt; &lt;/td&gt; &lt;td&gt;&lt;input type="checkbox"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;? } ?&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre>
 

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