這裏是我的問題加載數據:jQuery的標籤:當標籤處於活動狀態使用AJAX
的問題
我已經使用jQuery,這是非常相似jQueryUI的或Twitter的白手起家的標籤上創建標籤。頁面上有3個選項卡:「今日」,「本週」,「本月」。當你點擊「今日」標籤時,你會看到今天提交的所有帖子。和其他2個標籤類似地工作。它正在工作,所有的數據加載,但我不希望用戶等待數據花費這麼多時間來加載。 (如果每個標籤下有10個帖子,那麼這個頁面會加載30個帖子),爲了節省時間,我想用jQuery AJAX在特定標籤處於活動狀態時獲取帖子,或者用簡單的話說,當用戶點擊時在標籤上,帖子應該使用AJAX加載。
我在想什麼
是的,我知道我可以創建爲3個不同的網頁,但使用AJAX點擊選項卡時,我應該怎麼加載數據?這是我的HTML(使用JavaScript)代碼:
<script type="text/javascript">
$(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;
});
});
</script>
<ul class="tabs">
<li><a href="#today">Today</a></li>
<li><a href="#week">This Week</a></li>
<li><a href="#month">This Month</a></li>
</ul>
<div class="tab_container">
<div id="today" class="tab_content">
<!--Load the Content from today.php-->
</div>
<div id="week" class="tab_content">
<!--Load the Content from week.php-->
</div>
<div id="month" class="tab_content">
<!--Load the Content from month.php-->
</div>
</div>
更多信息
- 請爲我剛開始學習AJAX更好地理解代碼。
- 我正在使用PHP和MySQL。
- 應使用POST方法發送數據。
- 請嘗試使用jQuery AJAX。
你一定要明白,這是一個Q&A網站,而不是有人寫你的代碼的網站?你可能會得到一些關於這方面的正確方法的指針,但我懷疑有人會爲你寫出整個系統足夠的慷慨...... – BenM