简体   繁体   English

JQuery Ajax联系人表单问题

[英]JQuery Ajax Contact Form Issues

Can anybody help me with this? 有人可以帮我吗? I am not highly proficient in coding but know enough to get by. 我不是很精通编码,但是足够了解。 The issue is that the form can be filled out but in the telephone number field it won't accept spaces and 2) when it is filled out properly it does not return a value of "submitted". 问题在于可以填写表格,但是在电话号码字段中将不接受空格; 2)正确填写表格后,它不会返回“已提交”的值。

Any help is greatly appreciated..... 任何帮助是极大的赞赏.....

    $("#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;
    });

and the PHP code 和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';
    }

}
?>

your data is the wrong syntax you need to define it and then put the key in it ie 您的data是错误的语法,您需要先定义它,然后将密钥放入其中,即

data: {str: str},

http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.ajax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM