更新了頁面標題。使用AJAX調用特定的PHP函數
這是在Leaderboard.php上。你可以看到我目前在tbody中獲得了PHP調用。
<!-- The Leaderboard Table -->
<table id="tblData" class="table table-hover leaderboard-table target">
<thead>
<tr>
<th class="hidden-phone">Rank</th>
<th>Sales Person</th>
<th>Total Points</th>
</tr>
</thead>
<tbody id="leaderboardresults">
<?php $getLeaderboard->getTable($_GET['competitionId']); ?>
</tbody>
</table>
<!-- The Leaderboard Table END -->
這是API/getLeaderboard.php。這是getTable函數的地方。
<?php
class getLeaderboard {
public function getTable($competitionId) {
//I run the SQL query and echo out some PHP
}
這是在Leaderboard.php上。
function loadLeaderboard() {
var competitionId = $("body").attr("data-competitionId");
var url = "api/getLeaderboard.php?competitionId=" + competitionId;
$.get(url, function(data) {
//$("#leaderboardresults").html(data);
});
}
這也是上Leaderboard.php。另一個AJAX調用可以完成AJAX(這很好用),並且應該在成功時重新加載排行榜。
$(function() {
//this works (/James)
$(".navVisible").click(function() {
var Competition = $("body").attr("data-competitionId");
var Activity = $(this).attr("data-activity");
$.post("registerresults.php", { data: Activity, competitionId: Competition })
.done(function(data) {
loadLeaderboard();
});
});
loadLeaderboard();
});
這是getLeaderboardTable.php
<?php
include "common/common.php";
include "api/getLeaderboard.php";
$competitionId = $_GET['competitionId'];
$getLeaderboard->getTable($competitionId);
?>
看起來你忘了問一個問題? – BenM
是的,對不起。函數loadLeaderboard()是我想要的幫助。使用多個公用函數從文件(getLeaderboard.php)調用一個特定函數(getTable)。 – user2656127