以下是我用于submitHandler的代码:
submitHandler: function() {
$('.holder').fadeOut('slow');
$('#loading').fadeIn('slow');
$.post('email.php',{name:$('#em_name').val(), email:$('#em_email').val(), message:$('#em_message').val()},
function(data){
$('#loading').css({display:'none'});
if( data == 'success') {
$('#callback').show().append('Message delivered successfully');
$('#emailform').slideUp('slow');
} else {
$('#callback').show().append('Sorry but your message could not be sent, try again later');
}
});
}
与此php一起使用时无效:
<?php $name = stripcslashes($_POST['name']);
$emailAddr = stripcslashes($_POST['email']);
$message = stripcslashes($_POST['message']);
$email = "Message: $message \r \n From: $name \r \n Reply to: $emailAddr";
$to = 'mail@example.com';
$subject = 'Message from example';
//validate the email address on the server side
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailAddr) ) {
//if successful lets send the message
mail($to, $subject, $email);
echo('success'); //return success callback
} else {
echo('An invalid email address was entered'); //email was not valid
}
?>
有没有人有任何建议,为什么这不应该像它应该的那样工作。它似乎只是在我提交时锁定。任何帮助,将不胜感激。谢谢!
答案 0 :(得分:1)
建议
获取firebug或httpfox来调试ajax脚本。您可以查看所有请求和发布/获取变量。
请勿使用eregi使用preg
请勿使用preg验证电子邮件使用php's filter functions
另一个调试思路:在email.php代码上方设置$ _POST vars,并访问浏览器中的email.php,看看它是否正常工作。