I have tried to run an AJAX call within a PHP file, which sends data to another PHP file on the server that is taken from an html input when I press the submit button. Unfortunately when I click on the button, nothing happens, not even in the console. I have tried to debug the issue by creating a window.alert()
of the input within the AJAX call, but it somehow shows a certain "object Object" result in the alert box. I have tried to change the path to see if the file is being detected or not, but it seems it is being detected as when I deliberately add a wrong path it throws a 404, and even tried to add echo calls to the PHP file being called but nothing appears. The only issue I can really think of now is something wrong with my implementation, but I'm not sure what it is.
Update: I have tried looking up certain questions such as here and here, but they don't work for me
Code from where the AJAX calls are being made:
<?php
require "../../../AutoLoader.php";
use mvcApplication\core\controllers\ControllerFactory;
?>
<script>
$(document).ready(function () {
$('#submit').click(function () {
$.ajax({
url: '../app/views/generic/deletefunc.php',
type: 'GET',
data: {
Id: $('#Id'),
value: "0"
},
processData: false
});
});
});
</script>
<br>
<br>
<center>
<h3>Enter Teacher ID:</h3><input type="text" id="Id"
placeholder="Input ID here"/>
<br>
<button class="col-sm-4" id="submit">Submit</button>
</center>
<br>
deletefunc.php (code where the data should be received)
<?php
require_once '../../../AutoLoader.php';
use mvcApplication\core\controllers\ControllerFactory;
function deleteTeacher($a)
{
echo $a;
$entity = ControllerFactory::initTeacherC();
$entity->delete($a);
}
function deleteStudent($a)
{
echo $a;
/*$entity = ControllerFactory::initStudentC();
$entity->delete($data);*/
}
function deleteCourse($a)
{
echo $a;
/*$entity = ControllerFactory::initCourseC();
$entity->delete($data);*/
}
if (isset($_GET['Id']) && isset($_GET['value'])) {
switch ($_GET['value']) {
case "0":
deleteTeacher($_GET['Id']);
break;
case "1":
deleteStudent($_GET['Id']);
break;
case "3":
deleteCourse($_GET['Id']);
break;
}
}