This is the ajax code: clicking on a button opens that function and saves the id of that button in a variable called id. Then it is assumed that with ajax that id is sent to form.php but I get the following error:
Notice: Undefined index: id
$("button").click(function(){
var id = $(this).attr("id");
$.ajax({
url: 'form.php',
method: "POST",
data: {id : id},
success: function() {
$("#form").load("form.php");
}
});
});
Here the PHP code of form.php
<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
$id = $_POST['id'];
echo $id;
?>
Thanks