I am trying to call a PHP script using ajax when I click a certain button on the screen. The script will display data in a table that it fetches from an object that contains information fetched from a database in MySQL. I have tested all files separately and they seem to be working perfectly, displaying the tables and the data with no errors. I require one of the files in my main index file which works correctly, but when i try to call any of the files from an anchor/button on the browser it gives an internal server error (500) on the console. I assume there may be an error in the way I am using ajax, or something I may be missing in all this perhaps?
header.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-->
student/List.php (other list.php are pretty much the same):
<?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";
Index.php:
require_once '../AutoLoader.php';
require '../app/views/student/List.php';
Update : Solved! Thanks to @ZainFarooq 's comment. I needed to put AutoLoader.php
in Lists
file as well. The problem was with the paths i forgot to change the paths while requiring it in the Lists
files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.