Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Tabs : Load Data when Tab is Active using AJAX
    primarykey
    data
    text
    <p>Here is my problem:</p> <h1>The Problem</h1> <p>I have created Tabs using jQuery which is very similar to that of jQueryUI or Twitter Bootstraps's Tabs. There are 3 Tabs on page: "Today", "This Week", "This Month". When you click on "Today" tab, you'll see all the posts submitted today. And other 2 tabs work similarly. It's working, all the data loads but I don't want the users to wait for the data to take so much time to load. (If there are 10 posts under each tab, then the page is loading 30 posts), to save their time, I want to use jQuery AJAX to fetch the posts when a specific tab is active, or in simple words, when a user clicks on the tab, the posts should load using AJAX.</p> <h1>What I am Thinking</h1> <p>Yes, I know I can create 3 different pages for that, but how should I load the data using AJAX when the Tab is clicked? Here is my HTML (with javascript) Code:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { //When page loads... $(".tab_content").hide(); //Hide all content $("ul.tabs li:first").addClass("active").show(); //Activate first tab $(".tab_content:first").show(); //Show first tab content //On Click Event $("ul.tabs li").click(function() { $("ul.tabs li").removeClass("active"); //Remove any "active" class $(this).addClass("active"); //Add "active" class to selected tab $(".tab_content").hide(); //Hide all tab content var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content $(activeTab).fadeIn(); //Fade in the active ID content return false; }); }); &lt;/script&gt; &lt;ul class="tabs"&gt; &lt;li&gt;&lt;a href="#today"&gt;Today&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#week"&gt;This Week&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#month"&gt;This Month&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div class="tab_container"&gt; &lt;div id="today" class="tab_content"&gt; &lt;!--Load the Content from today.php--&gt; &lt;/div&gt; &lt;div id="week" class="tab_content"&gt; &lt;!--Load the Content from week.php--&gt; &lt;/div&gt; &lt;div id="month" class="tab_content"&gt; &lt;!--Load the Content from month.php--&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <h1>More Info</h1> <ul> <li>Please include the code for better understanding as I have just started learning AJAX.</li> <li>I am using PHP and MySQL.</li> <li>The data should be sent using POST method.</li> <li>Try to use jQuery AJAX, please.</li> </ul>
    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