When I call the POST function on the same page it's being submitted on it echo's what I submitted but when I try and echo it on the page it's submitted to it doesn't appear.
Everything is the same as it appears except the "include" function that calls the full url.
The Page:
<script>
$(function () {
$('form#PTan').on('submit', function(e) {
$.ajax({
type: 'POST',
url: '/submittest.php',
success: function (o) {
console.log(o)
alert('MUST ALERT TO DETERMINE SUCCESS PAGE');
}
});
e.preventDefault();
});
});
</script>
<form action='' id='PTan' method='post'>
<select class='formstyle' id='PTan' name='PTan'>
<option value='Beige'>Beige</option>
<option value='Dark'>Dark</option>
<option value='Light'>Light</option>
</select>
<input type='submit' name='submit' value='Submit' />
</form>
<?php
$PTan = $_POST['PTan'];
echo $PTan;
include "/submittest.php";
?>
Submittest.php
<?php
$PTan = $_POST['PTan'];
echo $PTan;
?>
Did you missed jquery library ? if yes add it to the <head></head>
<script>
$(function () {
$('form#PTan').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: '/submittest.php',
data: $('#PTan').serialze(), //Add data attr to the ajax function
success: function (o) {
console.log(o);
alert('MUST ALERT TO DETERMINE SUCCESS PAGE');
}
});
});
});
<form action='' id='PTan' method='post'>
<select class='formstyle' id='P' name='PTan'>
<option value='Beige'>Beige</option>
<option value='Dark'>Dark</option>
<option value='Light'>Light</option>
</select>
<input type='submit' name='submit' value='Submit' />
</form>
Your server side code is trying to examine $_POST['PTan']
, but you haven't sent that in the Ajax request.
$.ajax({
type: 'POST',
data: {
"PTan": "something"
},
url: '/submittest.php',