I'm trying to use Ajax to send some form data, but on the PHP page it's not echoing. I'm new to Ajax so not sure if I have done something wrong with it.
Here's what I have:
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'two.php',
data: $('form').serialize(),
success: function () {
alert('form was submitted');
}
});
});
});
One of the form fields has a name="selection" and id="selection" but in two.php all I'm trying to do is simply:
echo $_POST['selection'];
But nothing is set.
Any ideas?
console.log(data);after your alert, in two.php try$data = $_POST; $arrdata = array(); for each($data as $row) { $arrdata[] = $row; } var_dump($arrdata);