I am trying to get the return from the mail.php but it does not work. What am I missing here?
this is my form
<form name="myform" id="myform" action="" method="POST">
<input type="text" name="email" id="email" size="30" value=""/>
<input type="submit" name="button" id="button" value="Αποστολή">
</form>
and this is the script
$(function() {
$("#myform").submit(function() {
$.post('mail.php', function(data) {
$('#results').html(data); });
});
});
this script works correctly with jQuery Validate
$(document).ready(function(){
$("#myform").validate({
submitHandler: function(form) {
// do other stuff for a valid form
$.post('mail.php', $("#myform").serialize(), function(data) {
$('#results').hide().html(data).fadeIn('slow');
});
}
});
});
Cancel the form submission because you are already doing it in ajax.
Update
This is how it should look like without validation:
The difference is you are sending the serialized data from (with
$("#myform").serialize()) the form. In the previous code you were not sending any variables. Serializing meangs it will take the values of the forms and concatenate them into a single string. Read more about this here: http://api.jquery.com/serialize/