I have a very simple form that has an input field for first name. I captured the form data and transmitted it via ajax to a PHP page using the standard jQuery posting method. Ho
In your Ajax function, you're passing the contents of formData
to the server, though not as formData
but as their original input name.
In this case, you have:
The input's name is firstName, so you need to call $_POST['firstName']
instead of $_POST['formData']
.
if (isset($_POST['firstName'])) {
$ajaxData = $_POST['firstName'];
echo $ajaxData;
}
The same applies for any other field you would have in your form, so for example, having another input with the name lastName
means you'd have to call $_POST['lastName']
to access it.
There were also some misplaced brackets and parentheses in the PHP code which I accommodated above.