JQuery Ajax联系人表单问题

JQuery Ajax Contact Form Issues

本文关键字:问题 表单 联系人 Ajax JQuery      更新时间:2023-09-26

有人能帮我一下吗?我在编码方面不是很精通,但我知道的足以应付。问题是,表单可以填写,但在电话号码字段中,它不接受空格,2)当它正确填写时,它不返回值"已提交"。

任何帮助都非常感谢.....

    $("#ajax-contact-form").submit(function() {
        var str = $(this).serialize();      
        var href = location.href.replace(/dark'/|video'/|slider'/|contact'.html/g,'');
        $.ajax({
            type: "POST",
            url: href + "contact_form/contact_process.php",
            data: str,
            success: function(msg) {
                // Message Sent - Show the 'Thank You' message and hide the form
                if(msg == 'OK') {
                    $(this).addClass('success').find('span:eq(1)').html('success'); 
                } else {
                    $(this).addClass('error').find('span:eq(1)').html('error'); 
                }
            }
        });
        return false;
    });

和PHP代码

<?php
include dirname(dirname(__FILE__)).'/mail.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post){
    $name = stripslashes($_POST['name']);
    $email = trim($_POST['email']);
    $phone = stripslashes($_POST['phone']);
    $message = stripslashes($_POST['message']);


    $mail = mail(CONTACT_FORM, $phone, $message,
         "From: ".$name." <".$email.">'r'n"
        ."Reply-To: ".$email."'r'n"
        ."X-Mailer: PHP/" . phpversion());

    if($mail){
        echo 'OK';
    }
}
?>

您的data是错误的语法,您需要定义它,然后将密钥放入其中,即

data: {str: str},
http://api.jquery.com/jQuery.ajax/