So normally I can get my ajax to work without any issues however for some reason my script isnt passing variables through to my PHP form. Ive been trying to debug for a while and am hoping a fresh set of eyes can point out whatever dumb error I got going on (i stripped it to bare bones for simplicity, this wont pass variable).
AJAX + FORM
$('#formid').on('submit', function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: 'page.php',
data: $(this).serialize(),
success: function(data) {
alert(data);
}
});
});
<form id="formid" method="post">
<input type="text" name="name">
<input type="submit" value="Add">
</form>
PAGE.php
//Get Variables
$name = $_POST['name'];
echo 'Name is: '.$name;
This should display an alert that says 'Name is (whatever the user puts in the form)'
However it does not echo back what the user submits in the form. Can anyone see something wrong with this script?
Something is wrong with posting the data back to the php page data: $(this).serialize()