当我通过AJAX单击按钮时,我正在尝试使用PHP变量加载HTML文档。但是,完成此操作后,页面为空白,没有回调数据。
用于加载Ajax文件的链接集在
之下<a class="nav-link active" id="dash" href=""><i class="fas fa-chart-bar icon"></i> <span class="text">Dashboard</span></a>
<a class="nav-link" id="myProfile" href=""><i class="fas fa-cogs icon"></i> <span class="text">My Profile</span></a>
<a class="nav-link" href=""><i class="fas fa-users icon"></i> <span class="text">Users</span></a>
<a class="nav-link" href=""><i class="fas fa-graduation-cap"></i> <span class="text">Subjects</span></a>
<a class="nav-link" href=""><i class="far fa-calendar-alt"></i> <span class="text">Bookings</span></a>
<a class="nav-link" href=""><i class="fas fa-list-ul"></i> <span class="text">Reviews</span></a>
<a class="nav-link" href=""><i class="fas fa-comments"></i> <span class="text">Messages</span></a>
<a class="nav-link" href=""><i class="fas fa-question"></i> <span class="text">Support</span></a>
<a class="nav-link text-danger" id="logout" href=""><i class="fas fa-sign-out-alt icon"></i> <span class="text">Logout</span></a>
我要加载的示例是在名为dashboard.php
的页面中,其中包含以下内容放置在.dashContent
div中。
dashboard.php
:
<div class="row">
<div class="col-sm-6 col-xs-12 text-center">
<h1><?php echo $fullName; ?></h1>
<img src="../images/placeholder.png" class="profileImage">
</div>
<div class="col-sm-6 col-xs-12 text-center">
<h1>What's New?</h1>
<!-- Some Alerts for information -->
<div class="alert alert-success">New Users Today</div>
<div class="alert alert-success">Messages Today </div>
<div class="alert alert-success">Lessons Planned for Today</div>
<div class="alert alert-info">New Tutor Requests</div>
</div>
以下代码将包含用于加载Ajax的JavaScript函数和用于加载的gif,如下所示:
function dashAjax(){
$("#dash").click(function(e) {
e.preventDefault();
$("#spinner").show();
$(".dashContent").html("");
setTimeout(function(){
dashRequest();
}, 1500);
});
}
function dashRequest() {
$("#spinner").hide();
$(".dashContent").load("dashboard.php");
}
变量$fullName
存储在index.php
页面的顶部,就像这样 - &gt; $fullName = getFullName($user);