表单上的AJAX引用错误


AJAX reference error on form

我有以下AJAX脚本,这是我的页面上的联系人表单

$(function() {
    // Get the form.
    var contactForm = $('#contactForm');
    // Get the messages div.
    var formMessages = $('#form-messages');
    // Set up an event listener for the contact form.
    $(form).submit(function(e) {
        // Stop the browser from submitting the form.
        e.preventDefault();
        // Serialize the form data.
        var formData = $(form).serialize();
        // Submit the form using AJAX.
        $.ajax({
            type: 'POST',
            url: $(form).attr('action'),
            data: formData
        })
        :
        :

 <form id="contactForm" name="contactForm" action="php-scripts/contact-form.php" method="post">
           <label for="name">Name</label>
           <br />
           <input type="text" name="name" id="conName" />
           <br />
           <label for="email">Email</label>
           <br />
           <input type="text" name="email" id="conEmail" />
           <br />
           <label for="phone">Phone</label>

我的问题

在我的web控制台上,我得到错误:

ReferenceError: form is not defined

$(form).submit(function(e)

作为一个新手AJAX我不知道为什么我得到这个错误,任何帮助将被赞赏

如果您需要更多的信息来帮助,请告诉我

没有定义名为form的变量。最有可能在form -

附近丢失quote s
$('form').submit(function(e)

OR contactForm被定义

contactForm.submit(function(e)