当我单击屏幕上的某个按钮时,我试图使用ajax调用PHP脚本。该脚本将在其从对象中获取的表中显示数据,该对象包含从MySQL中的数据库中获取的信息。我已经分别测试了所有文件,它们似乎运行良好,可以正确显示表格和数据。我需要主索引文件中的一个文件才能正常工作,但是当我尝试从浏览器上的锚点/按钮调用任何文件时,控制台上会出现内部服务器错误(500)。我认为使用ajax的方式可能有错误,或者在所有这些内容中可能缺少某些东西?
header.php:
put
student / List.php(其他list.php几乎相同):
<!DOCTYPE html>
<html>
<head>
<title> Dashboard </title>
<link rel="stylesheet" href="../public/css/bootstrap.css"/>
<script src="../public/js/bootstrap.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script>
$(document).ready(function () {
$("#S").click(function () {
$.get("../app/views/student/List.php", function (data) {
$("#Content").html(data);
})
});
$("#C").click(function () {
$.get("../app/views/course/List.php", function (data) {
$("#Content").html(data);
})
});
$("#T").click(function () {
$.get("../app/views/teacher/List.php", function (data) {
$("#Content").html(data);
})
});
});
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">MVC</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" id="T">Teacher</a>
</li>
<li class="nav-item">
<a class="nav-link" id="S">Student</a>
</li>
<li class="nav-item">
<a class="nav-link" id="C">Course</a>
</ul>
</div>
</nav>
<div id="Content"> <!--this is closed in the footer file-->
Index.php:
<?php
require "../core/views/header.php";
use mvcApplication\core\controllers\ControllerFactory;
?>
<button class="col-sm-3" type="submit" onclick="">Add New</button>
<button class="col-sm-3" type="submit" onclick="">Edit Entry</button>
<button class="col-sm-3" type="submit" onclick="">Delete
Entry</button>
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Class</th>
</tr>
<?php
$init = ControllerFactory::initStudentC();
$data = $init->show();
foreach ($data as $d) {
//echo $d;
?>
<tr>
<td> <?php print $d['studentId'] ?></td>
<td> <?php print $d['name'] ?></td>
<td> <?php print $d['age'] ?></td>
<td> <?php print $d['gender'] ?></td>
<td> <?php print $d['class'] ?></td>
</tr>
<?php
}
?>
</table>
<?php
require "../core/views/footer.php";
答案 0 :(得分:0)
更新:已解决!感谢@ZainFarooq的评论。我还需要将AutoLoader.php
放入Lists
文件中。问题出在我Lists
文件中而我却忘记更改路径的情况下。