I've got a php script that I need to run using jQuery/AJAX when a user clicks a button. I have a jQuery script that is supposed to fire when the user clicks the button. However, the event isn't actually firing. Can anyone assist me?
instructor.php
<div id="instructor">
<?php
echo "<img id=instructor_image src=" .$_SESSION["image"] .">";
echo "<h1>" .$_SESSION["user"] ."</h1>";
echo "<span><p>" .$_SESSION["program"] ."</p> - <h2>" .$_SESSION["role"] ."</h2></span>";
echo "<a href=mailto:" .$_SESSION["email"] .">" .$_SESSION["email"] ."</a>";
?>
<button class="button" name="logout" id="logout">Logout</button>
</div>
script.js
$(document).ready(function(){
$("#logout").on("click", function(){
ajax = new XMLHttpRequest();
ajax.open("../php/logout.php", "POST", true);
ajax.send();
})
})
logout.php
<?php
require("../includes/header.php");
$loggedout = "UPDATE `$user_table` SET `logged_in`=0 WHERE `user_id`='$user_id'";
mysqli_query($connect, $loggedout);
session_unset();
session_destroy();
mysqli_close($connect);
header("Location: ../pages/logged_out.php");
?>
The session is started in the header and yes, the header is called on every page. I am also getting the following error on the ajax.open() line. NS_ERROR_ILLEGAL_VALUE: