I have a database of post office addresses. I have a page that will print the database in a table. I want to be able to update the address of the post office without reloading the whole page. I have a form to do this:
echo '<form id="AddressForm" method="post"><input type="hidden" name="form_PO" value="' . $row['PostOffice'] . '">Address: <input type ="text" name="submittedAddress"/><input name="submit" type="submit" value="Add"></form>';
(The form is in a while loop that prints the entire database, and an if statement that checks for an address and displays the form when address is empty)
I have an ajax script that I think is grabbing the POST data from the form and sending it to insert.php. My insert php works just fine as long as I manually set the post values. My problem is that it seems nothing is making it to insert.php.
Here's the ajax (blatantly stolen from another question):
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'insert.php',
data: $('form').serialize(),
success: function () {
});
});
)};
Here is how I'm trying to capture the post data in insert.php:
$selectedPO = $_POST['form_PO'];
$newAddress = $_POST['submittedAddress'];
I suspect I've made a rookie mistake in my ajax somewhere, but I've been unable to find it. Any details on how to debug such a thing would be useful.