I am trying to use JQuery AJAX to allow the user to input information into a form in a pop-over box, and then the information gets added to a MySQL database. However, for some reason, when I use the JQuery AJAX functions -- I've tried both $.post() and $.ajax() -- to POST the data, it does not get POSTed. Instead I get error messages of "Undefined index" for all the fields I tried to POST (when I go to processNewAssignments.php, which is the URL I am POSTing to). What am I doing wrong?
My JQuery AJAX function call when the user clicks to POST information is:
$.ajax({url: "[THIS CONTAINS THE REST OF THE URL]/processNewAssignments.php",
type: 'POST',
data: {max_grade: maxGradeValue, title: taskNameValue, due: dueDateValue}});
Or I have also tried:
$.post("[THIS CONTAINS THE REST OF THE URL]/processNewAssignments.php",
{max_grade: maxGradeValue, title: taskNameValue, due: dueDateValue});
My code for processNewAssignments.php (the URL the data is POSTed to) is:
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Process Assignments</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<?php
$maxgrade = $_POST["max_grade"];
$title = $_POST["title"];
$due = $_POST["due"];
$classID = $_SESSION["classID"];
echo "hello!";
echo $title . $classID . $due . $maxgrade;
require("db.php");
$query = "INSERT INTO assignments (title, assignmentID, classID, deadline, max_grade) VALUES ('$title', DEFAULT, '$classID', '$due', '$maxgrade')";
$result = mysql_query($query, $db);
?>