为什么我的提交表单带我到php页面


Why does my submit form take me to my php page?

(我没有意识到在此之前我已经发布的帖子可以编辑和重新打开。对过程感到困惑…)

当我点击发送表单时,电子邮件被正确发送,但随后我被发送到我的php页面显示数字0。我不明白为什么会这样。下面是(大部分)完整的代码:

<form id="contactForm" method="post" action="js/formCheck.php">
    <div class="formCol">
        <label>Email:</label>
        <input type="email" id="formEmail" name="email" autocomplete="off" placeholder="Your email address..." required/>
    </div>
    <div class="formCol midCol">
        <label id="floatMsg">Message (350 chars):</label>
        <textarea id="formMessage" name="message" rows="5" cols="40" maxlength="350" placeholder="What have you got to say?" required></textarea>
    </div>
    <div class="formCol lastCol">
        <input type="submit" class="submit-btn" name="submit" value="Send" />
    </div>
</form>

…脚本

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!--[if lt IE 9]><script src="js/modernizr.custom.js"></script><![endif]-->
<script src="js/jquery.flexslider-min.js"></script>
<script src="js/functions.js"></script>
<script>
    $(document).ready(function() {
        $('#form').ajaxForm(function() {
            alert("Thank you for your comment! I will receive it shortly and get back to you as soon as possible.");
            document.getElementById("form").reset();
        });
    });
</script>

SEND EMAIL (PHP)

if (isset($_POST['submit'])) {
    $email = htmlspecialchars($_POST['email']);
    $comment = htmlspecialchars($_POST['message']);

    /* Sending Email */
    $from_add = "Visitor";
    $to_add = "user@email.com";
    $subject = "The_Message_Subject";
    $message = "
        Message Information
        Email = $email
        Message = $comment";
    $headers = "From: $from_add 'r'n";
    $headers .= "Reply-To: $from_add 'r'n";
    $headers .= "Return-Path: $from_add 'r'n";
    $headers .= "X-Mailer: PHP 'r'n";
    mail($to_add, $subject, $message, $headers);
}

在表单重置后添加return false。而且形式id是contactForm而不仅仅是form

<script>
    $(document).ready(function() {
        $('#contactForm').ajaxForm(function() {
            alert("Thank you for your comment! I will receive it shortly and get back to you as soon as possible.");
            document.getElementById("form").reset();
            return false;
        });
    });
</script>