1

我想将 AJAX 实现为联系表单,这是我到目前为止的代码......

$("#contact_form").validate({
     meta: "validate",
     submitHandler: function (form) {
             $('#contact_form').hide();
             $('#sucessmessage').append("<h4 class='form_thanks'>Thanks, your email has been sent! We will get back to you as soon as possible</h4>");
             return false;
             form.submit();
     },
     /* */
     rules: {
             name: "required",

lastname: "required",
             // simple rule, converted to {required:true}
             email: { // compound rule
                     required: true,
                     email: true
             },
             subject: {
                     required: true,
             },
             message: {
                     required: true
             }
     },
     messages: {
             name: "Please enter your name.",
lastname: "Please enter your last name.",
             email: {
                     required: "Please enter email.",
                     email: "Please enter valid email"
             },
             subject: "Please enter a subject.",
             message: "Please enter a message."
     },
}); /*========================================*/
});

如何在其中实现 AJAX jQuery 代码(发布到 PHP 文件)?

谢谢

马特

编辑:对缩进感到抱歉,我比那更整洁,但我责怪 Dreamweaver!:P

4

1 回答 1

0

添加此功能:

$('#contact_form').submit(function(){
    $.post($(this).attr('action'), $(this).serialize(), function(data){
        // whatever you want to do post submit
    });
    return false;
});

虽然没有测试..您可能需要将它添加到“form.submit”部分,具体取决于代码其他部分的外观。

于 2012-08-27T23:00:50.777 回答