I am working with PHP and jQuery. I have 2 files
test.php
<script>
$(document).ready(function(){
$(".form-register").submit(function (e) {
var form_data = $(this).serialize();
e.preventDefault();
$.ajax({
type: "POST",
url: "test2.php",
data: form_data,
dataType: 'json',
success: function(){
alert(form_data);
}
});
});
});
</script>
<form class="form-register">
<input name="email" type="text"/>
<input name="name" type="text"/>
<input type="submit" name="register"/>
</form>
and the second file is test2.php
:
<?php
if(isset($_POST['register'])){
echo json_encode('Message from test2.php');
}else{
echo json_encode('post no received');
}
It seems like I am unable to retrieve $_POST['register']
because when I check alert(form_data);
only the email
and the name
are displayed.
Is there anyway for me to get $_POST['register']
?
</div>